Blue-Green vs Canary Deployment

Blue-green and canary are two common deployment strategies for releasing new versions without downtime. This article explains both flows and when to choose each, with a comparison table.

Overview

  • Blue-green: Two environments (blue, green). Current traffic hits blue; deploy new version to green; switch traffic to green. If problems occur, switch back to blue. Instant switch, fast rollback; doubles resource usage.
  • Canary: Deploy new version to a few instances; route a small fraction of traffic (e.g. 5%) to the new version. If stable, gradually increase to 100%. Gradual resource use; validates with low risk.
  • Choice: Need instant switch and very fast rollback → blue-green. Need gradual validation and lower risk → canary.

Example

Example 1: Blue-green flow

Plain text
Blue (v1) serves 100% → deploy v2 to Green → switch traffic to Green → Green serves 100%
If problems, switch back to Blue; else Blue can be decommissioned or become next Green

Example 2: Canary flow

Plain text
v1 100% → add v2 instances, 5% traffic → observe → 20% → 50% → 100%
On issue at any step: rollback (scale down v2, scale up v1)

Example 3: Comparison

DimensionBlue-greenCanary
SwitchInstantGradual
ResourcesDoubleProportional
RollbackSwitch backScale down new, scale up old
RiskFull cutoverSmall traffic first

Core Mechanism / Behavior

  • Blue-green: Two identical environments; LB or gateway switches traffic by config. No traffic during deploy to green.
  • Canary: Route by weight, header, or userId hash. Requires LB/gateway support for weighted or header-based routing.

Key Rules

  • Blue-green needs LB/gateway support for traffic switching; canary needs proportional routing (weight, header, userId hash).
  • Health checks and smoke tests before release; monitor latency and error rate during release; rollback promptly on anomalies.
  • Canary can combine with feature flags and A/B testing for finer control.

What's Next

See API Gateway and Load Balancing for traffic switching. See Service Discovery for instance registration and traffic removal.