Skip to content
$ lynuxpro
← All system designs

MID · 11 MIN · DEVOPS · SRE

Safe deployments: canary and feature flags

Shift traffic step by step, compare the canary with stable using real metrics, roll back automatically, and decouple deploy from release with flags.

Peak load
1,000 req/s service
Availability target
change failure < 15%
RTO: back up within
< 30 s rollback
RPO: data you can lose
0

← Swipe sideways to see the whole diagram →

ClientEdge / networkServiceInfrastructureData storeasync / background

The question

"Most of our incidents start with a deploy. Design a deployment system that catches bad releases before they hurt most users."

Requirements

  • New versions reach a small share of users first.
  • Automatic checks decide to continue or roll back, with no human watching graphs.
  • Rollback in under a minute.
  • Product teams can turn features on for some users without a deploy.

How it works

  1. The new version (canary) starts next to the stable version.
  2. A traffic router (ingress controller or service mesh) sends 5% of requests to the canary.
  3. The rollout controller (Argo Rollouts or Flagger) runs an analysis: error rate, p99 latency and SLO burn for the canary compared with stable, from Prometheus or Datadog.
  4. If healthy, it moves to 25%, 50%, then 100%, pausing at each step. If not, it sends all traffic back to stable automatically.
  5. Feature flags hide unfinished features inside the code; they can be turned on for staff, then 1% of users, and turned off instantly.

Remember it: deploy is shipping code; release is turning on the feature. Flags let you do them at different times.

Strategies compared

StrategyHowGood forCost
Rollingreplace pods a few at a timesimple appsbad version reaches everyone gradually
Blue-greenrun two full copies, switch all trafficinstant switch and rollbackdouble capacity during deploy
Canarysmall % first, grow on good metricscatching problems with real trafficneeds good metrics and routing
Feature flagcode is deployed but offproduct launches, kill switchesflag cleanup work

What breaks and how it heals

  • Too little traffic to judge the canary: run analysis longer, or use synthetic tests too.
  • Database changes: use expand-and-contract migrations so old and new versions both work during the rollout.
  • Bad config, not code: treat config changes like code: reviewed, gradual and reversible.

Load and capacity: is 5% enough to judge?

ItemAssumptionResult
Service traffic1,000 requests/sthe canary at 5% gets 50 requests/s
Analysis window10 minutes30,000 canary requests
Normal error rate0.1%~30 errors expected
Bad release1% errors~300 errors: a clear signal in 10 minutes
Full rollout5% → 25% → 50% → 100%, 10 min eachabout 40 minutes

High availability during deploys

TargetNumberHow it is met
Rollback timeunder 30 secondsthe controller moves traffic weights back to stable; no new pods needed
Extra capacity during a rollout+5-10%canary pods run beside stable pods
Change failure rateunder 15% (DORA "elite" teams: lower still)automatic analysis catches bad releases at 5% traffic
Data safetyno lost writesexpand-and-contract database migrations: old and new versions both work

What interviewers listen for

  • Metrics-based automatic promotion and rollback.
  • Backward-compatible database changes.
  • Separating deploy from release with feature flags.