How blue-green and canary deployments work, when to choose each, how to handle databases, and the mistakes that break zero-downtime releases.
In this article
A blue-green deployment runs two identical production environments, "blue" (live) and "green" (the new version), and switches all traffic from one to the other in one step once green is verified. A canary deployment sends the new version to a small share of users first, watches the results and increases that share gradually. Blue-green gives you a fast, clean cut-over and an instant rollback; canary gives you a cautious, evidence-based rollout that limits the damage of a bad release.
Both exist to solve the same problem: deploying software without downtime and without betting everything on a single moment. This guide explains how each works, when to choose which, what they demand of your architecture, and how to avoid the traps, particularly around databases.
Why not just deploy over the top?
The simplest approach is to stop the old version and start the new one on the same servers. It is cheap, but it means a window of downtime, no easy way back if the new version misbehaves, and a high-stakes release process that teams learn to fear. Fear leads to infrequent releases, which makes each one larger and riskier. Safer deployment strategies break that cycle by making releases small, observable and reversible.
Blue-green deployments
How it works
- Blue is serving all production traffic.
- You deploy the new version to green, which is an identical, idle environment.
- You test green with smoke tests and, if useful, internal traffic.
- You switch the router, load balancer or DNS weighting so that production traffic goes to green.
- Blue is kept on standby for a period. If anything goes wrong, you switch back.
- Later, blue becomes the staging area for the next release.
A Kubernetes illustration
In Kubernetes, a Service selects pods by label. Running two Deployments with a version label, you can flip traffic by changing the selector:
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
version: green # change from "blue" to cut over
ports:
- port: 80
targetPort: 3000
Applying that change moves traffic in one step, and changing it back is the rollback. Managed load balancers on AWS and Azure offer equivalent target-group or backend-pool switching, and many platform services provide "deployment slots" that swap staging and production. You do not need Kubernetes for this pattern, and for many teams a simpler platform is a better fit; see Kubernetes: do you really need it?
Strengths
- Near-zero downtime.
- Rollback is a switch, not a redeploy.
- The new version is tested in a production-like environment before it takes traffic.
Limits
- Needs duplicate capacity during the switch, which costs money.
- It is all or nothing: every user moves at once, so a bug that testing missed hits everyone.
- Long-lived sessions and in-flight requests need handling.
- Shared databases complicate it, as explained below.
Canary deployments
How it works
The name comes from the canary in the coal mine. You release the new version to a small slice of traffic and compare it against the old version.
- Deploy the new version alongside the old one.
- Route a small proportion of requests, or a specific group of users, to the new version.
- Compare key signals: error rate, latency, business metrics.
- If healthy, increase the share in steps until it reaches all traffic.
- If unhealthy, route everything back to the old version and investigate.
Weighted routing is available in most modern load balancers, API gateways, service meshes and ingress controllers. As a conceptual example, a weighted configuration might look like this (syntax varies by tool):
route:
- destination: web-stable
weight: 95
- destination: web-canary
weight: 5
Tools such as Argo Rollouts and Flagger automate the stepwise promotion and abort decisions on Kubernetes, based on metrics you define.
Strengths
- Limits blast radius: only a small share of users meet a bad release.
- Real production traffic is the test, which catches issues staging cannot.
- Works well with automated analysis and gradual promotion.
Limits
- Demands good monitoring. If you cannot tell whether the canary is healthier or sicker than the baseline, you are guessing. See what to measure.
- Two versions run at once, so they must be compatible with each other and with the data layer.
- With low traffic, a small canary may not see enough requests to reveal problems.
- More moving parts: traffic splitting, analysis and promotion logic.
Choosing between them
| Factor | Blue-green | Canary |
|---|---|---|
| Traffic shift | All at once | Gradual |
| Rollback | Instant switch back | Route traffic back, small exposure |
| Extra capacity | Full duplicate environment briefly | A fraction at first |
| Risk exposure | Everyone, after pre-switch testing | A small share first |
| Monitoring needed | Good | Essential |
| Complexity | Lower | Higher |
| Best for | Predictable releases, strict cut-over moments | High-traffic services where risk should be limited |
They are not mutually exclusive. A common hybrid is to deploy to green, send a small canary share, and complete the switch once the metrics are healthy. A third option worth knowing is the rolling update, where instances are replaced a few at a time. It is the default on many platforms and needs no extra capacity, but it gives less isolation and slower rollback than either method above.
Feature flags are a complement: you deploy code to everyone but switch the new behaviour on for a limited audience, separating deployment from release.
The database problem
The hardest part of any zero-downtime strategy is data. Blue and green, or stable and canary, usually share one database, so both versions must work with the same schema. The standard answer is the expand and contract pattern:
- Expand: add new columns or tables in a backwards-compatible way. The old version ignores them.
- Migrate: deploy the new version that writes to both or reads from the new structure, and backfill data.
- Contract: once no old version is running, remove the obsolete columns in a later release.
Avoid destructive changes, such as renaming or dropping a column, in the same release that depends on them. A rollback is only safe if the old version still works against the current schema.
What you need in place first
- Automated builds and deployment. Manual steps make switching error-prone. A CI/CD pipeline should deploy the same artefact every time.
- Health checks. The router must know whether an instance is ready, otherwise it sends traffic to something still starting.
- Repeatable environments. Blue and green must be identical, which is far easier with infrastructure as code and containers (see Docker for business teams).
- Observability. Dashboards and alerts that compare versions.
- A tested rollback. Practise it before you need it.
Common mistakes
- Environments that are not really identical. Configuration differences between blue and green defeat the purpose.
- Forgetting background jobs. Two versions both processing the same queue can duplicate or conflict. Plan how workers and scheduled tasks switch.
- Breaking the schema. The usual cause of failed rollbacks.
- Decommissioning blue too soon. Keep it until you are confident, including through a normal business cycle.
- A canary too small or too short. It must see enough traffic, across enough time, to show a problem.
- Judging by the wrong metric. A canary can have healthy HTTP codes but broken business behaviour, such as failed payments. Include business signals.
- Session breakage. If users are pinned to server-side sessions, a switch can log them out. Use shared session storage or stateless tokens.
- Cache surprises. A cold cache on green can cause a load spike at cut-over. Warm it first.
Summary
Use blue-green when you want a clean, reversible switch, and canary when you want to limit risk by exposing a small slice of users first. Both rely on automation, honest monitoring and backwards-compatible database changes. If you would like help designing a release process that fits your application and budget, CloudWiss's cloud and DevOps services cover CI/CD pipeline automation, load balancing and the monitoring that makes safe deployment practical.
Share this article
General educational information, not legal or professional advice for your specific situation.
