The idea in one minute#
Progressive delivery exposes a change to a small share of traffic first, compares its behaviour against the current version, and only widens the rollout if it looks healthy. A canary runs the new version alongside the old with a small traffic share (1%, 5%, 25%…). Blue/green runs a full copy of the new version and switches all traffic at once, keeping the old one ready for instant switch-back.
The hard part is the decision: is the canary worse? Comparing a canary’s error rate with the baseline needs enough requests to be statistically meaningful — with too little traffic, random noise looks like a regression, and real regressions hide in the noise. Automated canary analysis (Kayenta, Argo Rollouts analysis, Flagger) makes this decision from metrics, and rolls back without waiting for a human.
An analogy#
Miners took a canary into the mine: if the air was bad, the bird reacted long before the miners were harmed. A canary release lets a small, known share of users (or, better, internal users) meet the new version first — with someone watching closely and ready to pull everyone out.
A picture#
flowchart LR
T[":envoyproxy: <b>Traffic split</b><br/><small>mesh, ingress or LB</small>"] -->|"95%"| BASE[":kubernetes: <b>Stable</b><br/><small>v41</small>"]
T -->|"5%"| CAN[":kubernetes: <b>Canary</b><br/><small>v42</small>"]
BASE --> M[":prometheus: <b>Metrics</b><br/><small>errors, latency per version</small>"]
CAN --> M
M --> AN{":argo: <b>Analysis</b><br/><small>canary worse than baseline?</small>"}
AN -->|"healthy: next step"| T
AN -->|"worse: abort"| RB["Rollback to v41"]
class T io
class BASE compute
class CAN queue
class M memory
class AN queue
class RB warnHow it really works#
Strategies#
| Strategy | How | Pros | Cons |
|---|---|---|---|
| Rolling update | Replace instances a few at a time (Kubernetes default) | Simple, no extra capacity | No real comparison; a bad version reaches everyone gradually |
| Canary | Small traffic share to the new version, increased in steps | Limited blast radius; real comparison | Needs traffic splitting and analysis |
| Blue/green | Two full environments; switch all traffic | Instant cut-over and switch-back | 2× capacity during the switch; all users switch at once |
| Shadow (dark) traffic | Copy requests to the new version, discard its responses | Zero user impact | Only for read-only/idempotent paths; double load |
| Ring / cohort | Internal users → beta → one region → all | Real users who tolerate risk go first | Needs user-level routing |
A canary plan#
step 1: 1% for 10 min (catches crashes, obvious errors)
step 2: 5% for 15 min (enough traffic for statistics on error rate)
step 3: 25% for 30 min (latency, resource usage at real load)
step 4: 50% for 30 min
step 5: 100%
At every step: automated analysis; abort → rollback.Start in the canary cell or zone (7.c), and for services with users in many time zones, make sure a step spans meaningful traffic — a canary at 3 a.m. local time sees little.
Comparing canary and baseline#
- Compare against a baseline started at the same time with the same traffic share, not against the long-running stable fleet: the stable fleet has warm caches and long-lived connections; new pods do not. (Netflix’s Kayenta pattern: deploy a fresh baseline next to the canary.)
- Use the SLIs (error ratio, latency percentiles) plus resource signals (CPU per request, memory growth, GC time).
- Test whether a difference is statistically significant — with enough requests — and practically significant (a 0.01% error increase may be real but irrelevant).
How many requests do you need? To detect an increase in error rate from p₀ to p₁ with a
two-proportion test, the number of requests per side is roughly:
n ≈ (z_α + z_β)² × (p₀(1−p₀) + p₁(1−p₁)) / (p₁ − p₀)²To detect 0.1% → 0.3% errors (a tripling) at 95% confidence (one-sided) and 80% power you need about 6,000 requests in each group. At 1% of a 200 req/s service — 2 req/s — that takes nearly an hour; detecting a doubling (0.1% → 0.2%) needs about 18,000, over two and a half hours. That is why the first step catches only crashes and the statistical decisions happen at 5–25%.
Tools#
Argo Rollouts replaces a Deployment with a Rollout that has steps and analysis:
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: checkout
spec:
replicas: 20
strategy:
canary:
canaryService: checkout-canary
stableService: checkout-stable
trafficRouting:
istio:
virtualService: { name: checkout, routes: [primary] }
steps:
- setWeight: 1
- pause: { duration: 10m }
- setWeight: 5
- analysis:
templates: [{ templateName: error-rate }]
- setWeight: 25
- pause: { duration: 30m }
- setWeight: 50
- pause: { duration: 30m }
# selector and template as in a Deployment …
---
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
name: error-rate
spec:
metrics:
- name: error-ratio
interval: 2m
count: 5
failureLimit: 1
successCondition: result[0] < 0.002
provider:
prometheus:
address: http://prometheus.monitoring:9090
query: |
sum(rate(http_requests_total{service="checkout-canary",code=~"5.."}[2m]))
/ sum(rate(http_requests_total{service="checkout-canary"}[2m]))Flagger does the same for standard Deployments, driving Istio, Linkerd, Gateway API or ingress controllers. Spinnaker with Kayenta pioneered automated canary analysis. Cloud-native equivalents exist (AWS CodeDeploy, Google Cloud Deploy).
Blue/green details#
- The switch is a load balancer or DNS change; DNS switches are slow (TTLs) — prefer LB.
- Keep blue running until green has proven itself; switching back is the rollback.
- Both versions must work with the same database schema (expand/contract, 9.c).
- Long-lived connections must be drained (6.f).
A worked example#
Checkout v42 has a bug: one payment method fails, raising the error rate from 0.10% to 0.35%.
- Rolling update: within 10 minutes all pods are v42; the SLO burn alert pages after the budget has taken the hit (2.d); rollback takes another 10 minutes.
- Canary with analysis: at 1% the difference is invisible (too few requests). At 5% (10 req/s), after 15 minutes the canary has ~9,000 requests: 32 errors versus an expected 9. The analysis rejects it; Argo Rollouts aborts and shifts traffic back. Users affected: 5% for 15 minutes, instead of 100% for 20.
The program performs that analysis: required sample size, and a two-proportion z-test on the canary and baseline counts.
Code#
// canary.go — sample size for a canary and a two-proportion z-test on canary vs baseline.
package main
import (
"fmt"
"math"
)
// requiredN returns requests needed per group to detect p0 → p1 (one-sided α, power 1−β).
func requiredN(p0, p1, zAlpha, zBeta float64) float64 {
return math.Pow(zAlpha+zBeta, 2) * (p0*(1-p0) + p1*(1-p1)) / math.Pow(p1-p0, 2)
}
// zTest returns the z score for "canary error rate is higher than baseline".
func zTest(errC, nC, errB, nB float64) float64 {
pC, pB := errC/nC, errB/nB
p := (errC + errB) / (nC + nB)
se := math.Sqrt(p * (1 - p) * (1/nC + 1/nB))
return (pC - pB) / se
}
func main() {
const zAlpha = 1.645 // 95% one-sided
const zBeta = 0.84 // 80% power
fmt.Println("Requests needed per group to detect an error-rate increase:")
for _, c := range [][2]float64{{0.001, 0.002}, {0.001, 0.003}, {0.001, 0.01}, {0.01, 0.02}} {
n := requiredN(c[0], c[1], zAlpha, zBeta)
fmt.Printf(" %.2f%% → %.2f%%: %7.0f requests (at 2 req/s: %5.1f h, at 10 req/s: %5.1f h)\n",
c[0]*100, c[1]*100, n, n/2/3600, n/10/3600)
}
fmt.Println("\nCanary analysis at each step (baseline = fresh pods with the same traffic share):")
steps := []struct {
name string
errC, nC, errB, nB float64
}{
{"1% for 10 min", 4, 1200, 1, 1200},
{"5% for 15 min", 32, 9000, 9, 9000},
{"healthy release at 5%", 11, 9000, 9, 9000},
}
for _, s := range steps {
z := zTest(s.errC, s.nC, s.errB, s.nB)
verdict := "not significant: continue (or wait for more data)"
if z > zAlpha {
verdict = "SIGNIFICANTLY WORSE: abort and roll back"
}
fmt.Printf(" %-22s canary %.2f%% vs baseline %.2f%% z=%5.2f %s\n",
s.name, 100*s.errC/s.nC, 100*s.errB/s.nB, z, verdict)
}
}Notice the first step: 4 errors versus 1 looks like a 4× regression, but with 1,200 requests it is not significant. A rule like “abort if the canary has more errors than the baseline” would abort healthy releases all the time; a statistical test with enough data does not.
Remember this#
- Canary: small share, compare, widen in steps; blue/green: full copy, switch, switch back.
- Compare against a fresh baseline with the same traffic share, using SLIs and resource signals.
- Statistics matter: detecting small error increases needs thousands of requests per group.
- Automate the decision (Argo Rollouts, Flagger, Kayenta) and the rollback.
- Early steps catch crashes; statistical decisions happen once there is enough traffic.
Try it#
- Run
canary.go. How long would the 0.1% → 0.2% detection take at 1% of a 200 req/s service? - Install Argo Rollouts in a
kindcluster and run the demo rollout with a failing analysis. - Write the canary plan for a low-traffic service (20 req/s). What would you change?
Check yourself#
- Why compare a canary with a fresh baseline instead of the existing fleet?
- A canary has 3 errors in 500 requests, the baseline 1 in 500. Should you abort?
- What does blue/green require of the database schema?
- Why does the first canary step only catch large failures?