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.
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 |
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, optionalprePromotionAnalysis,autoPromotionEnabled, andscaleDownDelaySecondsto 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.