System design concepts · Running It for Real

Deployment Strategies: Blue-Green, Canary, Feature Flags

Most outages aren't caused by hardware or traffic. They're caused by us: a deploy, a config push, a migration. Safe change is a design problem, not just a DevOps chore.

What you'll be able to explain
  • Lay out a deployment pipeline from commit to production
  • Compare rolling, blue-green and canary releases, and when to use each
  • Separate deploying code from releasing features with flags
  • Change databases, APIs and events without downtime
  • Treat configuration and infrastructure as reviewed, versioned code

Why change is the main risk

Industry post-mortems keep finding the same thing: a large share of production incidents start with a change. That's good news, because change is the one risk factor fully under your control. A design that makes change small, gradual, observable and reversible removes most of the danger.

Analogy

Changing a live system is like changing a tyre on a moving car. You can't stop the car, so you build tools that let you swap one wheel at a time, watch the steering after each one, and put the old wheel back in seconds if the car starts to wobble.

The delivery pipeline

1 · Commit + reviewSmall pull request, reviewed by a teammate, with tests2 · Build onceCompile, unit-test and package an immutable artefact (container image)3 · TestIntegration and contract tests against real dependencies in staging4 · Deploy to canaryA small slice of production traffic gets the new version5 · Progressive rollout1% → 10% → 50% → 100%, with automated health checks between steps6 · Observe + auto-rollbackError rate or latency regress? Roll back without waiting for a human
A typical path from commit to production. Each stage is a gate that can stop a bad change.

Principles that matter more than any specific tool:

  • Build once, deploy many: the exact artefact tested in staging is the one that reaches production. No rebuilding per environment.
  • Small batches: deploying 3 changes is far safer than deploying 300, because when something breaks you know which change did it.
  • Automate the rollback: humans are slow at 3 AM. Health checks should be able to halt and reverse a rollout on their own.
  • Deploy during working hours, with the author around. Freeze changes before big events.

Deployment strategies

Strategy How Rollback Extra capacity Risk exposure
Recreate Stop all old, start all new Redeploy old None Everyone, plus downtime
Rolling Replace instances a few at a time Roll forward/back gradually ~10–25% Grows with each batch
Blue-green Run the full new version alongside; switch traffic at once Switch back instantly 2× during switch Everyone at the switch moment
Canary Send a small % of traffic to the new version, watch, then expand Route canary traffic away Small Only the canary slice
Shadow (dark launch) Copy real traffic to the new version; discard its responses Nothing to roll back Varies None to users
CLIENTUsersNETWORKLoad balancerweighted routingSERVICEv1 (stable)95%SERVICEv2 (canary)5%OKCanary analysiserrors, p99, business KPIs95%5%metricsmetrics
A canary release: 5% of traffic goes to v2 while automated analysis compares its health with v1.
Tip

Canary analysis should compare the canary against the current version at the same time, not against yesterday. Traffic patterns change through the day; a side-by-side comparison isolates the effect of the change. Include a business metric (checkouts per minute), not just error rates.

Deploy is not release: feature flags

A feature flag is a runtime switch that decides whether code paths are active. With flags, you can:

  • Deploy dark: ship code to production turned off; turn it on later without a deploy.
  • Release gradually: 1% of users, then employees only, then a city, then everyone.
  • Kill instantly: turn off a misbehaving feature in seconds, without a rollback.
  • Experiment: A/B test variants and measure the effect.
Flag type Lifetime Example
Release flag Days to weeks new_checkout_ui
Experiment flag Weeks price_display_variant_b
Ops / kill switch Permanent disable_recommendations
Permission flag Long-lived beta_features_for_tenant_42
Common trap

Flag debt. Every flag doubles the number of possible code paths. Release flags that have been at 100% for a month are dead weight and a source of bugs. Give every release flag an owner and an expiry date, and delete it once the rollout is done.