Skip to content

Rolling, blue-green and canary deploys

Working knowledgeConcept

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:

A rolling update, one instance at a time
Step 1 of 13
Serving v2 0
Instance slots (4 wanted, room for 1 extra)
v1
v1
v1
v1
–
  • 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).

4 serving v1

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:

deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
spec:
replicas: 4
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1 # at most 5 instances during the rollout
maxUnavailable: 0 # never fewer than 4 ready
selector:
matchLabels: { app: api }
template:
metadata:
labels: { app: api }

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.

Blue-green: two full environments, one router
Before the switch
users
router
blue v1 ×4live
green v2 ×4tested
  • 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.

A typical canary schedule (example numbers)
StageTraffic to v2WaitGo on if
11%10 minv2 error rate and p99 latency no worse than v1’s
210%30 minSame checks, now with enough requests to trust them
350%30 minSame checks, plus business numbers such as sign-ups
4100%–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

The three side by side
MeasureRollingBlue-greenCanary
Extra capacityOne batchA full second copyA few instances
Versions live togetherYes, during the rolloutNo, apart from the switchYes, by design
Who sees a bad releaseA growing shareEveryone, until you switch backThe canary slice
RollbackAnother rolloutFlip the routerSend the slice back
RollingMinutes to undoUndo replaces every instance again, as slowly as the deploy did.
Blue-greenSeconds to undoThe old version is still running. You point traffic back at it.
CanaryFew users hitProblems are caught while only the slice sees v2, then that slice is moved 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.

One step
-- deploy v2 and this together
ALTER TABLE users
RENAME COLUMN name TO full_name;
-- v1 instances still read users.name: errors
Expand, then contract
-- release 1: add, write both, backfill
ALTER 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 column
ALTER 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.

08 Check yourself

Question

A Deployment has replicas: 4, maxSurge: 1 and maxUnavailable: 0. What is the most instances that can exist during the rollout?

Question

A release has a bug that hurts every user. Which strategy limits how many users it reaches before you notice?

Question

You rename a column in the same release as the code that uses the new name, and deploy with a rolling update. What goes wrong?

09 Practise this

Was this tutorial useful?Your vote tells us what to improve next.
Spotted a mistake, or something unclear?