download

When should a 5% canary trigger an automatic rollback?

DevOps~12 minReviewed 2 Dec 2026Free · No sign-in

Question

You deploy orders-api v4.2 as a 5% canary for 15 minutes while 95% of traffic stays on v4.1. Both cohorts receive the same live traffic mix:

CohortShareRequests (15 min)5xx errors5xx ratep99 latency
Baseline (v4.1)95%95,0001900.20%140 ms
Canary (v4.2)5%5,000751.50%310 ms
  1. Should the rollout promote or roll back, and why does the service-wide 5xx average hide this regression?
  2. What automated rollback criteria should you set (including minimum sample size)?
  3. Why can a database schema change break rollback, and how do you keep rollbacks safe?
Show hints (3)
  1. "CHECK BLENDED AVERAGE"

    Compute (190 + 75) / 100,000. See how small the shift looks globally even though canary errors jumped 7.5x.

  2. "GATE ON SAMPLE SIZE"

    Compare canary directly against live baseline on error rate and p99 latency, but wait until canary has enough requests (such as 1,000) so one stray error does not flap.

  3. "SAFE SCHEMA ROLLOUT"

    If v4.2 drops or renames a column that v4.1 reads, rolling back crashes 100% of pods. Split schema work into expand, migrate, and contract steps.

Show checked explanation

Roll back immediately. Across 5,000 requests, canary 5xx errors jumped 7.5x (1.50% vs 0.20%) and p99 latency more than doubled (310 ms vs 140 ms). The blended rate moved only from 0.20% to 0.265%. Gate rollouts against live baseline with a minimum sample size, and use expand-and-contract migrations.

"SOLUTION · PYTHON"
def canary_gate(base_req, base_err, base_p99, can_req, can_err, can_p99):
    if can_req < 1_000:
        return "WAIT: insufficient sample"
    base_rate = base_err / base_req
    can_rate = can_err / can_req
    reasons = []
    if can_rate > max(base_rate * 2, base_rate + 0.005):
        reasons.append(f"5xx {can_rate:.2%} vs {base_rate:.2%}")
    if can_p99 > base_p99 * 1.5:
        reasons.append(f"p99 {can_p99}ms vs {base_p99}ms")
    return "ROLLBACK: " + ", ".join(reasons) if reasons else "PROMOTE"


print("v4.2:", canary_gate(95_000, 190, 140, 5_000, 75, 310))
print("small:", canary_gate(95_000, 190, 140, 20, 1, 145))
print("clean:", canary_gate(95_000, 190, 140, 5_000, 11, 150))
"OUTPUT"
v4.2: ROLLBACK: 5xx 1.50% vs 0.20%, p99 310ms vs 140ms
small: WAIT: insufficient sample
clean: PROMOTE

Canary vs baseline rates, blended total, two-proportion z-score, and Python 3.12 canary gate code run on CPython 3.12.10 (Windows x64) and checked against Google SRE canary guidance. Checked by an editor other than the author.

Walkthrough

Never judge a 5% canary by the service-wide average. Across all 100,000 requests, total 5xx errors are 190 + 75 = 265, or 0.265% (just +0.065 points above baseline). That tiny blended bump looks like normal jitter. Inside the canary cohort, however, the error rate surged 7.5x (1.50% vs 0.20%) and p99 latency jumped 2.21x (310 ms vs 140 ms, +170 ms). At 100% traffic (100,000 requests), baseline produces 200 errors every 15 minutes, whereas promoting v4.2 would jump that to 1,500.

Automated rollback criteria compare canary against live baseline at the same time, not against yesterday's metrics (traffic shape shifts by hour). Pair three checks:

  1. Minimum sample gate: Require enough requests (here >= 1,000) and time (10 to 15 minutes). That way, a tiny sample like 1 error in 20 requests (5%) returns WAIT instead of flapping.
  2. Error rate threshold: Combine relative and absolute margins (> max(2 * baseline, baseline + 0.5%), here 0.70%) so ultra-low baselines (0.01%) do not trip on tiny counts while real regressions (1.50%) fail fast.
  3. Latency and saturation guards: Trip rollback if canary p99 exceeds 1.5x baseline (210 ms) or if memory/CPU climbs sharply.

Keeping rollback safe with database migrations. Code rolls back in seconds; destructive SQL does not. If v4.2 runs ALTER TABLE orders DROP COLUMN legacy_tax, rolling back to v4.1 breaks 100% of baseline pods that still query legacy_tax. Use expand-and-contract across separate releases:

PhaseReleaseWhat changesSafe to roll back?
ExpandSchema migration (v4.1 unchanged)Add new nullable column; keep old column liveYes (v4.1 ignores new column)
Migratev4.2 + backfillDual-write both columns; backfill old rows; read new with fallbackYes (roll back to v4.1; old column stays populated)
Contractv4.3, then cleanup migrationv4.3 stops writing old column; drop column only after rollback window closesTo v4.2 before drop; not after drop

Every code deploy remains forward- and backward-compatible with its active database schema.

Common mistakes

  • Watching only the aggregate service dashboard during a 5% canary. A 7.5x regression in 5% of traffic shifts the blended rate by only 0.065 points.
  • Comparing canary to yesterday's metrics instead of a concurrent live baseline. A daytime traffic change or external outage looks like a bad release.
  • Triggering rollback with no minimum sample floor. One error out of 20 early requests reads as 5% and aborts healthy releases.
  • Running destructive DROP COLUMN or column-rename migrations inside the same release as app code, making rollback crash baseline pods.

Follow-up questions

  • "Why compare a fresh canary pod against a freshly restarted baseline pod when testing latency?" Long-running baseline pods have warm JIT code, filled caches, and pooled connections. Comparing a cold canary pod against warm baseline pods can falsely blame v4.2 for cold-start latency.
  • "What if a bug only fires once per hour, such as a memory leak or a cron job?" A 15-minute canary will miss slow leaks. Use stepped soak stages (for example 5% for 15 minutes, 25% for 1 hour, then 100%) and watch memory growth slope, not just 5xx rate.
  • "Should canary traffic stick to the same user or split randomly per request?" Stick by user or session when UI state or multi-step API payloads differ between versions. Random per-request routing works well for stateless endpoints, while sticky routing prevents mixed-version session bugs.

What a strong answer covers

Spots that blended 5xx (0.265%) hides a 7.5x canary error spike and 2.21x p99 regression across 5,000 requests. Defines concurrent canary-vs-baseline gates with a minimum sample floor, and uses expand-and-contract migrations so rollbacks never break data.

Open in interactive practice deck →

Original OfferVibe question. Canarying Releases · Kubernetes Deployments.
© 2026 OfferVibe · Text CC BY-NC-SA 4.0 · code MITFree to share and adapt with credit, not for commercial use. Code samples are free for any use.