Blue-green deployment keeps two production-capable environments: blue (live) and green (idle candidate). You deploy the new version to green, run checks, then shift user traffic from blue to green in one controlled step. If metrics go wrong, you shift back.
The goal is not zero work—it is predictable cutovers without long outages caused by in-place upgrades on a single fleet.
When blue-green beats rolling updates
Rolling updates replace instances gradually. That works for stateless apps tolerant of two versions at once. Blue-green helps when:
- You must validate the full stack before any customer hits it.
- Schema migrations are risky and you want a fast rollback path.
- Compliance wants a clear audit trail of which build received traffic and when.
It costs more infrastructure because you temporarily run double capacity. For many teams the insurance is worth it during major releases.
Reference architecture on AWS
A practical layout:
Route 53 (optional weighted records)
|
Application Load Balancer (two target groups)
| |
Blue ASG / ECS service Green ASG / ECS service
| |
Shared data tier (RDS, DynamoDB, ElastiCache)
Both colors talk to the same data plane unless you invest in duplicate databases for true isolation. Shared databases simplify operations but mean migrations must stay backward compatible during the switch window.
Elastic Beanstalk
Beanstalk has a built-in blue-green toggle via environment swap. Clone the environment, deploy to the clone, run health checks, then swap CNAMEs. Good for teams already on Beanstalk who want guardrails without writing custom automation.
ECS and CodeDeploy
ECS blue/green uses CodeDeploy to manage target group weights on an ALB. You define:
- Primary task set (blue)
- Replacement task set (green)
- Listener rules shifting from 100/0 to 0/100
CodeDeploy can bake time—hold traffic on green at 10% while CloudWatch alarms watch error rate and latency.
EKS
Kubernetes often combines blue-green with Service selectors or a progressive delivery controller (Argo Rollouts, Flagger). The pattern is the same: two Deployments, one Service that flips label selectors after health checks pass.
The deployment playbook step by step
- Build artifact once – Same container image or AMI tags green and blue for traceability.
- Provision green – Scale green to match blue capacity; verify tasks pass load balancer health checks.
- Smoke and synthetic tests – Hit green through an internal header, separate listener, or VPN-only rule so production users stay on blue.
- Shift traffic – Move ALB weights or Route 53 records. Prefer gradual shifts (10 → 50 → 100) when releasing risky changes.
- Watch golden signals – Error rate, p95 latency, queue depth, and business KPIs (checkout success).
- Decommission or freeze blue – Keep blue warm for quick rollback during a soak period, then scale down to save cost.
Document who can approve step 4 and which alarms auto-trigger rollback.
Database and state: where cutovers break
Blue-green is easy to diagram and hard to execute when state is involved.
Backward-compatible migrations
Use expand/contract patterns:
- Expand: Add nullable columns or new tables while blue still runs old code.
- Deploy green with code that writes both old and new shapes if needed.
- Contract: Remove old columns after green is stable.
Never drop a column the old color still reads.
Sessions and caches
Sticky sessions on blue break when users land on green. Prefer centralized session stores (Redis, DynamoDB) or stateless JWTs with short TTL.
Flush caches carefully. A cold cache on green can look like an outage if databases cannot absorb traffic spikes.
Feature flags vs color
Feature flags toggle code paths inside one environment. Blue-green swaps entire environments. Combine them: use flags for incremental exposure, blue-green for large infrastructure or dependency changes.
Rollback that actually works
Rollback fails when teams destroy blue immediately. Keep blue idle but deployable for at least one business day. Automate reverse weight shifts:
# Illustrative AWS CLI pattern — adjust names to your stack
aws elbv2 modify-listener \
--listener-arn "$LISTENER_ARN" \
--default-actions Type=forward,TargetGroupArn="$BLUE_TG_ARN"
Run rollback drills quarterly. Measuring time-to-recover matters more than claiming zero downtime.
Observability checklist
- ALB
HTTPCode_Target_5XX_Countper target group - ECS
CPUUtilizationand task count per service - Synthetic canaries hitting critical flows every minute
- Deployment annotations in logs (
deployment_id,color,git_sha)
Correlate CloudWatch alarms with CodeDeploy deployment IDs so on-call engineers know which color to drain.
Cost and capacity planning
Blue-green doubles compute during the overlap window. Mitigations:
- Run green smaller during testing, scale to parity only before cutover.
- Use Spot for green non-production soak environments (not for the cutover instant unless you accept interruption risk).
- Schedule big swaps off-peak while still staffing incident response.
Security and compliance notes
Green must receive the same IAM roles, secrets, and WAF rules as blue. Drift between colors creates silent vulnerabilities the moment traffic moves.
Rotate secrets in both colors when vendors force expiry; do not assume blue's credentials automatically copy to green clones.
Alternatives to consider
| Strategy | Strength | Weakness |
|---|---|---|
| Rolling | Cheapest capacity | Two versions coexist |
| Blue-green | Fast rollback | Double infra cost |
| Canary | Fine-grained risk | More routing complexity |
| Immutable ASG replace | Simple mental model | Slower rollback |
Pick based on blast radius tolerance, not buzzwords.
Testing green before you bet the business
Treat pre-cutover testing as a release gate, not a nice-to-have. A practical sequence:
- Contract tests against downstream sandboxes while green still receives zero customer traffic.
- Replay production traffic safely using captured requests with sensitive fields scrubbed; tools like GoReplay or custom shadow listeners on the ALB help compare responses between colors.
- Load tests at expected peak plus headroom; green should not be the first time you learn a memory leak exists.
Record baseline metrics from blue during the same test window so you compare apples to apples.
Communication templates that prevent panic
When traffic moves, support and leadership hear rumors before they read dashboards. Send a short status note with:
- What changed (version, time window)
- How to detect issues (symptoms, not internal codenames)
- Who owns rollback authority
If you use a status page, schedule maintenance only when customers might notice added latency during warm-up—not for invisible backend swaps.
FAQ
Is blue-green the same as active-passive DR?
Related idea, different goal. DR sites tolerate long failover; blue-green targets minutes-level promotion within the same region.
Can serverless use blue-green?
Lambda aliases and weighted versions implement similar traffic shifting. API Gateway stages canary routes to new versions before full promotion.
Do microservices need synchronized colors?
Not always. Contract tests and API versioning let teams move services independently, but customer-facing flows spanning many services may need coordinated gates.
Blue-green deployment on AWS is less about duplicating hardware and more about practicing traffic surgery—rehearsed shifts, measured rollback, and schema discipline so the green environment is truly safe before it becomes production.
Further Reading
Discover more articles on similar topics across our network
Comments
Loading comments…