Deployment strategies (canary, blue-green, flags)
Ship changes to a small slice first, watch the metrics, then widen or roll back automatically; separate deploy from release with feature flags, and change schemas in backward-compatible expand/contract steps.
How it works
- Roughly 70% of outages come from changes (Google SRE): limit the blast radius and undo fast.
- Rolling replaces instances in batches; blue-green flips all traffic between two full environments.
- Canary: give the new version a small slice, compare with the baseline, then widen or abort.
- Feature flags separate deploy from release: ramp per user or tenant, kill in seconds.
- Code rolls back, data doesn't: change schemas with expand/contract so both versions keep working.
Check yourself
Answer to mark it learned; your answers aren't scored.
Ten minutes into a 15-minute canary step, the canary (5% of traffic) shows a 2.1% error rate against 0.2% on the baseline. Latency looks the same. What should happen?
Go deeper
Full explanation
Roughly 70% of outages come from changes to a live system (Google SRE), so the goal is to limit the blast radius of a bad change and undo it fast.
- Rolling: replace instances in batches (Kubernetes defaults: 25% surge, 25% unavailable). Cheap, but old and new versions serve side by side, and rollback is another rollout.
- Blue-green: stand up a full new environment, flip the router, keep the old one idle to flip back instantly. Costs 2× capacity during the cutover.
- Canary: send a small slice (say 5%) to the new version, compare its errors and latency with the baseline, then widen step by step or abort automatically.
- Feature flags separate deploy (code is on the servers) from release (users see it): ramp per user or tenant, kill in seconds without a deploy.
- Dark launch: run the new path on real traffic but discard its output, to test load and correctness.
Data is the hard part: code rolls back, writes don't. Use expand/contract: add the new schema next to the old, migrate, and remove the old only when nothing reads it.
Code Canary with automated analysis (Argo Rollouts)
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: checkout
spec:
replicas: 20 # selector and pod template omitted
strategy:
canary:
analysis: # runs in the background during the steps
templates:
- templateName: success-rate
steps:
- setWeight: 5 # 1 of 20 pods without a traffic router
- pause: {duration: 15m}
- setWeight: 25
- pause: {duration: 15m}
- setWeight: 50
- pause: {duration: 15m} # then 100%
---
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
name: success-rate
spec:
metrics:
- name: success-rate
interval: 5m
failureLimit: 2 # repeated bad readings abort: weight back to 0
successCondition: result[0] >= 0.99
provider:
prometheus:
address: http://prometheus:9090
query: |
sum(rate(http_requests_total{app="checkout",code!~"5.."}[5m]))
/ sum(rate(http_requests_total{app="checkout"}[5m]))Real example
Knight Capital, 1 Aug 2012 (SEC order): new code was rolled out in stages to 8 servers, but a technician missed one. The new code reused an old flag that once enabled dead "Power Peg" logic, still present on that 8th server. Orders carrying the flag woke it up: ~4M executions in ~45 minutes and a loss of more than $460M. Mid-incident, removing the new code from the 7 good servers made it worse, because the flag kept arriving. Lessons: verify every target runs the build, never repurpose flags, delete dead code.
Trade-offs +3 · −3
+ You gain
- Canaries catch bad changes while they touch only a few percent of users.
- Blue-green gives near-instant code rollback: flip the router back.
- Flags make release a runtime decision: per-tenant ramps, experiments, kill switches.
− You pay
- Blue-green doubles capacity during the switch; canaries need good metrics and enough traffic to judge.
- Old and new versions coexist during rolling and canary, so APIs and schemas must stay compatible.
- Flags are debt: each one is a code path to test and, eventually, delete.
Use it when
Canary with automated analysis for any service with real traffic; blue-green for atomic cutovers you can afford to double; flags for risky features, gradual ramps and kill switches.
Avoid it when
A canary can't judge a service with almost no traffic. No strategy undoes one-way effects (destructive migrations, sent emails, payments): gate those with dry runs and flags.
Numbers to know 4
- Google SRE: roughly 70% of outages are due to changes in a live system.
- Kubernetes rolling update defaults:
maxSurge25% (rounded up),maxUnavailable25% (rounded down). - SRE workbook example: a change failing 20% of requests behind a 5% canary costs ~1% of all requests.
- CrowdStrike (Jul 2024): one content update crashed ~8.5M Windows devices (Microsoft's estimate); its remediation plan added canary, staged rollouts.
Common pitfalls 4
- Renaming a column in one deploy: mid-rollout, the old version still uses the old name and fails.
- Rolling back code after a migration the old code can't read: the rollback becomes the outage.
- Judging a canary on CPU or averages instead of user-facing errors and latency.
- Repurposing or never deleting flags: Knight Capital's reused flag woke dead code.
Interview questions 2
Answer out loud first, then reveal.
How do you roll back a deploy that included a database migration?Show answer
I design so the schema never needs rolling back. Migrations ship separately and stay backward compatible: expand first (add the new column, nullable), deploy code that writes both, backfill, switch reads, then contract (drop the old column) a release or two later. At every step the previous code version still works, so rolling back is just redeploying the old image. Destructive steps happen only once nothing reads the old shape.
Canary, blue-green or feature flags: which would you use?Show answer
They solve different problems, so usually several. A canary limits the blast radius of code and config changes: a small slice, automated comparison with the baseline, auto-abort. Blue-green fits an atomic cutover, like a runtime upgrade, when I can pay double capacity briefly. Flags control release: per tenant or percentage, with a kill switch that works in seconds. For a risky feature I deploy it dark behind a flag through a canary, then ramp the flag.