Blue-Green and Rolling Deployments
What you'll learn: How to safely deploy immutable infrastructure using parallel environments or gradual instance replacement strategies.
The Core Idea
When working with immutable infrastructure (where you replace entire servers rather than patching them), you need safe deployment strategies. Two popular approaches are blue-green deployments and rolling deployments, each offering different trade-offs between speed, safety, and resource usage.
Blue-Green Deployments
In a blue-green deployment, you maintain two identical production environments: "blue" (currently serving traffic) and "green" (idle). When deploying:
- Deploy your new version to the green environment
- Test green thoroughly while blue still handles all traffic
- Switch the load balancer to route traffic from blue to green
- Keep blue as a safety net for quick rollback if problems arise
Analogy: Like having two identical restaurant kitchens. While Kitchen A serves customers, you prepare new recipes in Kitchen B. Once confident, you redirect diners to Kitchen B instantly. If something's wrong, flip back to Kitchen A immediately.
Trade-offs: Requires double the resources temporarily, but offers instant rollback and zero-downtime deployments.
Rolling Deployments
In a rolling deployment, you gradually replace instances in your cluster:
- Take one or a few instances out of rotation
- Replace them with new immutable versions
- Verify they're healthy and serving correctly
- Repeat until all instances are replaced
Analogy: Like renovating a hotel one floor at a time while guests stay in other floors. Less disruptive but slower.
Trade-offs: Uses fewer resources (no doubling required) but rollback is slower since you must reverse the process. Brief periods may run mixed versions.
Key Takeaway: Blue-green deployments offer instant switchover and rollback at the cost of double resources, while rolling deployments conserve resources by gradually replacing instances, trading speed for efficiency.