Course contentsShow
← Software Engineering
Lesson 1476 of 1,93343. Infrastructure as CodeFree lesson

Blue-Green and Rolling Deployments

Deployment strategies for immutable infrastructure using parallel environments or gradual instance replacement.

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:

  1. Deploy your new version to the green environment
  2. Test green thoroughly while blue still handles all traffic
  3. Switch the load balancer to route traffic from blue to green
  4. 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:

  1. Take one or a few instances out of rotation
  2. Replace them with new immutable versions
  3. Verify they're healthy and serving correctly
  4. 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.