Programming
We provide developers and engineers the guides and tutorials they...
Search
We provide developers and engineers the guides and tutorials they...
Content is king. It's not just about how you're going to write, b...
Looking for an engaging connection with thousands of other people...
Blue-green and canary deployments explained: how each works, rollback, cost, database changes, feature flags and how to choose a release strategy.
Quick answer: Both strategies release a new version of software without downtime and with a fast way back. In a blue-green deployment, you run two complete, identical environments. The current version (blue) serves all traffic while the new version (green) is deployed and tested alongside it. Then you switch all traffic to green at once, keeping blue ready so that rolling back is just switching again. In a canary deployment, you send a small share of real traffic, perhaps 1%, to the new version, watch its error rates and latency, and increase the share step by step only if it stays healthy. Blue-green gives an instant switch and rollback; canary limits how many users a bad release can affect.
No test environment perfectly matches production. Real data, real traffic patterns and real scale reveal problems that tests miss. The simplest way to deploy, stopping the old version and starting the new one, has two flaws:
Modern strategies aim for three things: no downtime, a small blast radius, and fast rollback.
A rolling update replaces instances gradually: take one out, start a new one, check it is healthy, move on to the next. It is the default in Kubernetes.
Martin Fowler's description of blue-green deployment is the classic reference.
Strengths
Weaknesses
The name comes from the canaries once carried into coal mines to give early warning of dangerous gas. The practice is described in Canary Release.
Routing can be random, or targeted: internal staff first, then one region, then a percentage of everyone.
Strengths
Weaknesses
Google's SRE Workbook chapter on canarying releases covers how to choose the canary size, duration and metrics.
| Rolling update | Blue-green | Canary | |
|---|---|---|---|
| Traffic shift | Gradual, by instance | All at once | Gradual, by percentage |
| Extra infrastructure | Little | A full second environment | Little |
| Rollback | Roll back gradually | Instant switch | Instant: route away |
| Users exposed to a bad release | A growing share | Everyone | A small share |
| Real-traffic testing before full release | Partial | No | Yes |
| Complexity | Low | Medium | Higher |
| Monitoring needed | Basic | Basic | Strong |
Application code can be switched back in seconds. Data cannot. If the new version changes the database schema, the old version may no longer work, and rollback is no longer possible.
The standard technique is expand and contract, which spreads a change over several releases:
Every step is backwards-compatible, so every step can be rolled back. This applies to all three strategies, since each has old and new code running against the same database for some period.
The same goes for APIs and message formats between services: new versions must tolerate old ones.
A feature flag is a switch in the code that turns a feature on or off at run time, without deploying.
This gives canary-style gradual exposure at the level of a single feature, and lets incomplete work be merged safely. The cost is extra complexity: old flags must be cleaned up.
Related techniques:
Progressive delivery means the pipeline does the watching:
Tools such as Argo Rollouts and Flagger do this on Kubernetes, and service meshes and load balancers provide the fine-grained traffic splitting. All of it slots into a CI/CD pipeline.
Many teams combine them: a canary for the code rollout, flags for the feature release.
Blue-green switches all traffic at once between two complete environments. Canary shifts traffic gradually, starting with a small percentage, and expands only if the new version is healthy.
Canary limits how many users a bad release reaches. Blue-green offers the fastest full rollback. Which matters more depends on your traffic, monitoring and budget.
Not by themselves. Schema changes must be made backwards-compatible, typically with the expand-and-contract approach.
A run-time switch that turns a feature on or off without a new deployment, allowing gradual release and instant disabling.
Blue-green and canary deployments both make releasing safer, in different ways: one by making the switch and the rollback instant, the other by exposing a few users before everyone. Neither removes the need for backwards-compatible database changes or good monitoring. Start with rolling updates, add canaries where the stakes are high, and use feature flags to control what users actually see.