Opscraft
Deployment strategies · Lesson 4 of 10 · 4 min read

Blue-green deployments

The pattern

Run two identical environments:

  • Blue — current production, serving all traffic.
  • Green — new version, deployed and tested with no user traffic.

Switch all traffic to green at once. Keep blue running for a while; rollback is switching back — near-instant.

Enlarge diagramusersrouterALB rule orServiceBlue (v1)all traffic todayGreen (v2)deployed, smoke-tested, idleswitch
Figure 1. Blue-green: green is deployed and tested with no users; the switch moves all traffic at once, and switching back is just as fast.
Swipe sideways to see all of it, or tap to open it full screen.

Pros: instant cutover and rollback, full testing of green in production infrastructure before release, versions don't serve users simultaneously (mostly). Cons: roughly double capacity during the release, shared dependencies (database!) must work with both, every user gets the new version at once (big blast radius if tests missed something), and in-flight sessions/connections need draining at cutover.

Switching mechanisms

Layer How Switch speed
Kubernetes Service Two Deployments labelled version: blue/green; change the Service selector Seconds
ALB Point the listener rule's forward action at the green target group (or weighted 0/100) Seconds
DNS (Route 53) Change the record / weighted records Slow and uneven — resolver caching and TTLs
Whole environment (ASG, Beanstalk swap CNAME) Swap at the LB or DNS level Depends on layer
Enlarge diagramKubernetes Service selectorsecondsALB listener / target groupssecondsRoute 53 recordsminutes, uneven (caching)
Figure 2. Where to flip blue-green: at the load balancer or Service it takes seconds; with DNS, caches keep some users on the old side for minutes or more.
Swipe sideways to see all of it, or tap to open it full screen.

Prefer switching at the load balancer or Service level; DNS-based blue-green suffers from caching and clients that ignore TTL.

Kubernetes example:

apiVersion: v1
kind: Service
metadata: { name: orders }
spec:
  selector: { app: orders, version: green }    # was: blue
  ports: [{ port: 80, targetPort: 8080 }]

Test green first through a separate "preview" Service/Ingress (orders-preview) before flipping the main one.

Managing cost and risk

  • Keep green scaled small until just before cutover, then scale to full and switch; scale blue down after a bake period.
  • Or use canary instead if double capacity is unaffordable.
  • Run automated smoke and synthetic tests against green before the switch.
  • Pre-warm caches/JIT if the app has a cold-start penalty, otherwise latency spikes at cutover.

Tools

  • Argo Rollouts strategy.blueGreen — manages active and preview Services, optional prePromotionAnalysis, autoPromotionEnabled, and scaleDownDelaySeconds to keep the old ReplicaSet around for fast rollback.
  • Flagger — blue-green mode with traffic switching and analysis.
  • AWS CodeDeploy — blue/green for ECS (two target groups, test listener, hooks like AfterAllowTestTraffic) and for EC2/ASGs.