Compare deployment strategies — rolling, blue/green, canary, and feature flags — and explain how you'd choose per service.
Quick Answer
Rolling replaces instances gradually (cheap, default, weak blast-radius control); blue/green runs two full environments with instant traffic switch (fast rollback, 2x cost, all-or-nothing exposure); canary sends a traffic slice to the new version with metric-gated promotion (best blast-radius control, needs mature observability); feature flags decouple release from deploy entirely (per-user targeting, kill switches — plus flag-debt to manage). Choose by blast radius tolerance, observability maturity, and statefulness.
Detailed Answer
The decision inputs: (1) cost of a bad release — a tier-3 internal tool takes rolling; payments takes canary with automated verification; (2) rollback speed needed — blue/green's instant switch beats rolling's re-deploy; flags roll back in milliseconds without any deploy; (3) observability maturity — canary without trustworthy per-version metrics is theater; you need version-labeled error/latency signals and ideally automated analysis before canary buys you anything; (4) state — schema changes break naive blue/green (both environments share the database mid-transition; you need expand/contract migrations regardless of strategy); sticky sessions complicate canary traffic splitting; (5) traffic volume — a 1% canary on 100 rps is 1 request/second: statistical confidence needs minutes-to-hours, so low-traffic services often do better with blue/green + synthetic checks. Real systems compose them: deploy dark behind a flag (deploy≠release), canary the infrastructure rollout, then release progressively via flag targeting — with the flag as the instant kill switch. The named trap: feature-flag debt — stale flags multiply code paths and test matrices, so flags need owners and expiry like TODOs with teeth.
Code Example
# choose per tier, compose for tier-1:
tier3: rolling (maxUnavailable: 25%)
tier2: blue/green + smoke suite on green before switch
tier1: deploy dark (flag off) -> canary 5% infra -> flag ramp 1%->10%->100%
kill switch: flag off (ms) | infra rollback: previous ReplicaSetInterview Tip
Two senior signals: 'deploy ≠ release' (flags decouple them) and the expand/contract schema caveat that applies to every strategy — naming those beats reciting the four definitions.