Rolling, blue-green and canary deploys
Shipping a new version should not mean a minute of errors, and a bad release should be quick to undo. Here are the three common ways to get there, rolling, blue-green and canary, drawn step by step with what each one costs.
01 Why a restart means downtime
The simplest deploy stops the old version everywhere and starts the new one. Between the two, nothing answers. Requests in flight are cut off, and if the new version fails to start, you are down until someone puts the old one back.
Every strategy on this page avoids that gap the same way: start the new version before the old one stops, and move traffic over only once the new one has proved it is healthy. They differ in how much spare capacity that takes, how long both versions run side by side, and how fast you can go back.
02 Rolling: replace instances a few at a time
A rolling update swaps instances in small batches. It is the default for a Kubernetes Deployment and for most managed platforms, because it needs little extra capacity. Here is one with four instances:
- starting, no traffic
- just became ready
- drained and stopped
- free slot
Four instances run v1 behind a load balancer. The rollout may add one extra instance (maxSurge: 1) and may never drop below four ready ones (maxUnavailable: 0).
In Kubernetes the batch size comes from two settings on the Deployment. The readiness probe is what lets the rollout wait for each new instance instead of guessing:
Both settings default to 25% if you leave them out. Rolling back is just another rollout in the other direction (kubectl rollout undo deployment/api), so it takes about as long as the deploy did.
03 Blue-green: a second copy, then one switch
Blue-green keeps two complete environments. Blue serves users. You deploy v2 to green, run your checks against it, and when it looks right you point the router (a load balancer, DNS name or ingress) at green.
- taking real traffic
- ready, being tested
- the one switch
The release is one change at the router: point it at green. Rollback is the same change in reverse, as long as blue is still running.
All users move at once, and nobody sees a mix of versions at the router. The cost is double capacity during the release, and the risk is that everything moves at once: a bug you missed reaches everyone. Keep blue running until you are confident, because that is what makes rollback a single switch.
04 Canary: a small slice of real traffic first
A canary release sends a small share of real traffic to the new version and watches it before going further. If the error rate or latency of the canary is worse than the old version’s, you stop and send that slice back. Only a few users ever saw the problem.
| Stage | Traffic to v2 | Wait | Go on if |
|---|---|---|---|
| 1 | 1% | 10 min | v2 error rate and p99 latency no worse than v1’s |
| 2 | 10% | 30 min | Same checks, now with enough requests to trust them |
| 3 | 50% | 30 min | Same checks, plus business numbers such as sign-ups |
| 4 | 100% | – | v1 can be removed |
The comparison is the point: the canary is judged against the old version running at the same time, not against a fixed number. Splitting by user (a cookie or user id) rather than by request keeps one person on one version, which matters if v1 and v2 render pages differently. Tools such as Argo Rollouts and Flagger, or a service mesh, automate the steps and the checks.
05 Which one, and what it costs
| Measure | Rolling | Blue-green | Canary |
|---|---|---|---|
| Extra capacity | One batch | A full second copy | A few instances |
| Versions live together | Yes, during the rollout | No, apart from the switch | Yes, by design |
| Who sees a bad release | A growing share | Everyone, until you switch back | The canary slice |
| Rollback | Another rollout | Flip the router | Send the slice back |
06 What makes rollback actually fast
Each strategy promises an easy way back, but the promise only holds if v1 can still run against whatever v2 changed. The usual thing that breaks it is the database. Rolling and canary deploys run both versions at the same time, so the schema must suit both.
-- deploy v2 and this togetherALTER TABLE usersRENAME COLUMN name TO full_name;-- v1 instances still read users.name: errors
-- release 1: add, write both, backfillALTER TABLE users ADD COLUMN full_name text;UPDATE users SET full_name = name;-- release 2: read full_name only-- release 3, later: drop the old columnALTER TABLE users DROP COLUMN name;
With expand and contract, every release works with the schema before and after it, so any one of them can be rolled back. Two more habits help. Keep the previous build artefact (the image tag) so going back means redeploying something that already ran. And put risky features behind a feature flag: the code ships turned off, and you turn it on, or off again, without a deploy at all.
07 When it bites
no readinessProbeTraffic reaches instances that are not readyWithout a readiness check, the platform counts an instance as ready as soon as the process starts, before it has loaded config or warmed up. The rollout races ahead and users get errors.SIGTERMIn-flight requests cut offWhen an instance is stopped, the platform sends SIGTERM and later kills it. If the app exits at once, requests it was serving fail. Stop taking new requests, finish the current ones, then exit.v1 + v2 at onceTwo versions that cannot shareDuring a rolling or canary deploy, v1 and v2 serve together and read each other’s data, cache entries and queue messages. Change formats so both can read them, the same way as the schema.1% for 2 minutesA canary too small to tellWith little traffic, a real rise in errors looks like noise. Wait until the canary has handled enough requests to compare, or use a bigger slice.blue → greenBlue-green with a cold greenGreen has empty caches and new connection pools. Switching all traffic at once can overload it for the first minutes. Warm it up first, or move traffic in steps.Rollback only covers code. A migration that dropped a column or rewrote data does not roll back with the deploy, so make destructive schema changes their own, later release.