Deploy without downtime
A bad deploy hits 100% of users at once.
Say it like this
A bad build should hurt 1% of traffic for five minutes, not everyone, so I deploy the new version next to the old, shift a small weighted slice to it, compare its error rate and p99 with the old version, and only then widen or roll back.
Basic solution
Blue-green swaps traffic between two full environments; canary sends a small slice to the new version and watches error rates before widening.
Weighted slice, concurrent baseline, automatic rollback
The balancer sends 2.5% of traffic to canary instances; analysis compares them with the old version over the same window; a pass raises the weight, a breach drops it to zero while the old instances keep serving.
How it works
- The new build is deployed as its own set of instances alongside the current version. Both sets register with the load balancer, and the new set starts with zero or a very small weight, so almost no traffic reaches it yet.
- Traffic shifts by weight: the balancer sends 1% of requests to the canary instances and 99% to the old ones. Where a user must not switch versions mid-session, sticky routing keeps that user on one set for the session.
- Canary analysis compares the canary's metrics with a baseline taken from the old version over the same minutes: error ratio, p99 latency, saturation, and business metrics such as successful matches per minute. Comparing against the same window cancels out time-of-day effects.
- If the canary stays within tolerance for the hold period (10 to 30 minutes), the weight steps up: 5%, 25%, 50%, 100%. Each step repeats the comparison before the next.
- On any breach the balancer drops the canary weight to zero automatically. The old instances never went away, so rollback is a routing change that takes effect in seconds, not a redeploy.
- Blue-green is the two-step version. A complete second environment (green) is deployed and warmed, the balancer switches all traffic from blue to green at once, and blue stays running but idle so the switch can be reversed just as fast.
What must hold for either
- Both versions run at the same time against the same data, so database schemas, message formats and API contracts must be readable by both versions for the whole rollout.
Worked example
Ride matching service, new build with a changed scoring function
- Fleet: 40 matcher instances across 10 regions. Canary: 1 extra instance per region (10 in all) running the new build, at 2.5% weight, chosen so every region sees the new scoring on some requests.
- Baseline: the metrics of the 40 existing instances over the same 20-minute window, not last week's numbers, so time-of-day effects cancel out.
- Comparison thresholds: error ratio within 0.05 percentage points of baseline; p99 match latency within 10%; matches per minute per instance within 5%; offer acceptance rate within 2 points, the business signal that the scoring is not worse.
- Result at 2.5%: p99 up 40% (from 150 ms to 210 ms) because the new scoring calls the ETA service twice. The analysis fails the latency gate; the weight goes to zero after 20 minutes, affecting about 50K of 2M ride requests, none with errors.
- After the fix (batch the ETA calls): canary passes at 2.5%, 10%, 50%, 100% over two hours.
- Blue-green would have cost double the fleet (80 instances) for the switch window and would have exposed 100% of traffic to the latency regression at once; canary cost one extra instance per region.
Variants and when each wins
Rolling update
- Instances are replaced a few at a time by the orchestrator, with no explicit analysis step. It wins for routine deploys because it is cheap and built in; a bad build reaches 100% unless a human is watching the graphs.
Canary with automated analysis
- A weighted slice of traffic goes to the new build and a comparison against the concurrent old version gates each step, with automatic rollback. It wins for stateless services with enough traffic to compare within minutes.
Blue-green
- Two full environments with an instant switch and switch-back. It wins for low-traffic services where a 1% slice gives no statistical signal, and for changes that cannot run mixed with the old version, such as a runtime upgrade.
Shadow traffic
- Requests are duplicated to the new version and its responses are discarded. It wins for testing load and error behaviour with zero user exposure; it is only safe for idempotent reads.
Recommendation: rolling for routine deploys with a canary gate for user-facing services, blue-green for the rare change that cannot run two versions mixed.
Failure modes
Incompatible schema during the rollout
- Old instances crash when they read rows the new version wrote. It happens because the schema or message format changed in a single step that only the new version understands. Use expand-then-contract migrations, where every change stays readable by both versions until the old one is gone.
Canary too small to see the problem
- The canary passes and the full rollout fails. It happens because at 1% of traffic a failure that affects 0.1% of requests produces a handful of events, below the noise. Hold the canary longer, raise the slice, and compare business metrics that aggregate more signal per minute.
Comparing against the wrong baseline
- Every canary fails on Monday mornings. It happens because the comparison uses yesterday's metrics, when traffic was lighter, rather than the old version running right now. Take the baseline from the old version over the same window.
Sticky state on the canary
- Users bounce between behaviours mid-session, or their sessions break. It happens because requests are round-robined across versions while session state lives in instance memory. Make the services stateless, or pin each session to one version for the duration of the rollout.
Rollback that is not a rollback
- Routing traffic back to blue leaves behind bad data that green wrote. It happens because the deploy and the data migration were treated as one thing. Run data migrations separately from deploys, keep writes backward compatible, and have a data repair plan before the rollout starts.
Interviewer follow-ups
Answer out loud before you open each one.
Canary or blue-green for a service with 50 requests per second?
Blue-green. At 50 requests per second a 1% canary sees half a request per second, so a 20-minute hold yields 600 requests, too few to detect a 0.5% error rate. Switching everything to a warmed green environment with instant switch-back gives a clearer signal and a clean rollback.
How does a canary deploy coexist with a database migration?
The migration ships first as an additive change that both versions tolerate, then the canary rolls out code that uses the new column, and only after the old version is gone does a cleanup migration remove the old one. The deploy itself never changes the schema.
What metrics gate the canary, and what is the hold time?
Error ratio, p99 latency and saturation compared with the concurrent old version, plus one business metric that would reveal a silent logic bug. Hold until the canary has served enough requests to detect the smallest regression you care about, typically 10 to 30 minutes at each step.
How is this different from a feature flag rollout?
A canary slices by instance and tests the whole build, including dependency and runtime changes; a flag slices by user and tests one code path inside an already-deployed build. Use the canary for the deploy, then flags for risky features inside it.
Connections
The same parts on other clouds
The diagrams above name AWS services as one concrete example. Every part has a close equivalent elsewhere. In an interview, name the role first, such as “a managed Redis cache”, then the product you would pick.
| AWS | Used here as | Google Cloud | Microsoft Azure | Open source and others |
|---|---|---|---|---|
| Application Load Balancer | Load balancer | Cloud Load Balancing | Application Gateway, Azure Load Balancer | NGINX, HAProxy, Envoy |
| Amazon EC2 Auto Scaling | Old version ×40, Canary ×1 per region | Compute Engine managed instance groups | Virtual Machine Scale Sets | Kubernetes Deployment with a HorizontalPodAutoscaler, Nomad |