The riskiest moment in a release is the switch from old code to new. Blue-green deployment makes that switch a single, reversible step. You keep two production environments that are as identical as possible. Blue serves live traffic. You deploy the new version to green, test it there with production configuration, then point the router at green. Blue stays running, so if something breaks you point the router back.
How it works
- Blue runs version 1.8 and takes all traffic.
- The pipeline deploys version 1.9 to green. Green connects to the same database and dependencies.
- Smoke tests and health checks run against green through an internal address.
- The load balancer, DNS record or service selector switches to green. All new requests now go to 1.9.
- Blue stays up for a while as the rollback target. Once you are confident, it becomes the target for the next release.
Rollback is the same switch in reverse, so it takes seconds rather than a redeploy. That shortens MTTR for failed releases and is one reason teams with good DORA metrics use it.
Example: blue-green in Kubernetes
Run two Deployments, checkout-blue and checkout-green, each labelled with its colour. The Service decides which one gets traffic:
apiVersion: v1
kind: Service
metadata:
name: checkout
spec:
selector:
app: checkout
colour: blue
ports:
- port: 80
targetPort: 8080
After green passes its checks, one command moves all traffic:
kubectl patch service checkout -p '{"spec":{"selector":{"app":"checkout","colour":"green"}}}'
Patching the selector back to blue is the rollback. Tools such as Argo Rollouts automate the same pattern, including a preview Service for testing green first.
On AWS, Amazon RDS Blue/Green Deployments apply the same idea to databases. RDS keeps a green copy in sync through replication, so you can test an engine upgrade there and then switch over.
Blue-green vs canary vs rolling
| Strategy | How traffic moves | Rollback | Extra capacity |
|---|---|---|---|
| Blue-green | All at once, after testing green | Instant switch back | A second full environment during release |
| Canary | Gradually, for example 5%, 25%, 100% | Shift the small share back | A few extra instances |
| Rolling | Instances replaced in batches | Roll forward or redeploy the old version | Little or none |
Choose blue-green when you want a simple, fast rollback and can afford double capacity for a short time. Choose canary when you want real users to test the release on a small scale first. Many teams combine blue-green infrastructure with feature flags for risky features.
The database problem
Both colours usually share one database, so a schema change must work with old and new code at the same time. Use the expand and contract pattern: add new columns or tables first, deploy code that writes both, migrate data, and only drop the old structure in a later release. A migration that renames a column in place breaks blue the moment it runs, and then rollback no longer works.
Common mistakes
- Long-lived sessions or websockets that stay on blue after the switch. Drain connections deliberately.
- Background workers and scheduled jobs running in both colours and processing the same work twice.
- Letting green drift from blue in configuration, which defeats the point of testing it.
We build release pipelines with blue-green and canary rollouts as part of our cloud and infrastructure work.