Blue-Green Deployment
A zero-downtime deployment strategy that stands up an identical new environment (Green) alongside production (Blue) and atomically switches traffic after verification
Table of Contents
Structure Diagram
Two identical stacks · Atomic router cutover
- Traffic ShiftInstant 100% cutover at load balancer
- Rollback SpeedSeconds (flip router back to Blue)
- Infra Cost2× compute capacity during cutover
- Blast RadiusAll traffic hits new version at once
Small traffic slice · Metric-gated ramp
- Traffic ShiftGradual ramp (1% → 10% → 50% → 100%)
- Rollback SpeedAuto-drain canary weight back to 0%
- Infra CostLow (only small canary slice added)
- Blast RadiusContained to a tiny initial cohort
What is Blue-Green Deployment?
A zero-downtime deployment strategy that stands up an identical new environment (Green) alongside production (Blue) and atomically switches traffic after verification. It is a core concept in Deployment Strategies within Cloud / DevOps.
Core Principles
Blue-Green Deployment eliminates downtime by running two identical production environments side by side. While Blue serves live user traffic, the new release is deployed and smoke-tested in an isolated Green environment. Once health checks pass, the load balancer or router atomically flips 100% of traffic from Blue to Green.
Because Blue stays warm and intact immediately after cutover, recovering from a broken release takes seconds—simply route traffic back to Blue. It also avoids mixed-version states where two incompatible app versions serve requests simultaneously.
Practical Takeaways
- Use Expand-and-Contract for database migrations: Both Blue and Green usually share the same database. Never drop or rename columns during a single release, or rolling back to Blue will break production. Always expand (add nullable columns), migrate code, and contract (remove old columns) in a later release.
- Enable connection draining: Configure graceful shutdown and load-balancer deregistration delays (e.g., 30–60s) so in-flight requests finish cleanly on Blue during cutover instead of returning
502errors. - Keep Green ephemeral to control cloud spend: You don't need to pay for 2× servers 24/7. Spin up Green automatically inside CI/CD, validate, cut over, hold Blue for a short soak window, and tear Blue down once metrics stay healthy.
Notable Examples
- AWS CodeDeploy (ECS/ALB) & Azure Deployment Slots: Built-in target-group swaps with automated health checks and one-click rollbacks.
- Edge & frontend platforms (Vercel, Netlify, Cloudflare Pages): Immutable preview builds that become production via an atomic routing pointer swap.
- Financial & payment services: Mission-critical APIs where mixed-version concurrency is unacceptable and instant rollback is mandatory.
Practical Code Snippet
Copy and drop straight into your projectapiVersion: v1kind: Servicemetadata: name: web-prodspec: selector: app: web slot: green # Switch "blue" -> "green" for instant 100% cutover ports: - port: 80 targetPort: 3000