Topic 1 of 5 · 5 min read
Rollout plans with canaries and rollback
Goal: Write a rollout plan for a risky change with a canary stage, a rollback trigger and a reversible migration.
A safe rollout is a plan that limits who can be hurt, says in advance what failure looks like, and makes going back a single cheap step. Whether you or an agent wrote the change, you agree the exit before you enter.
Check yourself · 1 of 3
What is the main benefit of shipping a risky change behind a feature flag that starts off?
Why it matters
Most outages follow a change. Tests pass because they run on small data and clean inputs. Production has odd users, old rows and real traffic. An agent such as Claude Code, Codex or Cursor can produce a large, plausible change quickly, which makes the blast radius of one bad merge bigger, not smaller. A rollout plan keeps the damage small while you learn.
The four parts
- Ship dark behind a flag. Deploy the code with the new path switched off. Deploying and releasing become two separate decisions. Turning the flag off is then your fastest rollback, with no new build. Name an owner and a removal date for every flag.
- Expand in stages. Start with internal users, then a small slice of traffic (a canary), then half, then everyone. Hold at each stage long enough to see real traffic, including the slow daily peak.
- Write the rollback trigger before you deploy. Pick two or three signals from your dashboards and set numbers: "error rate above 1% for 5 minutes, or p95 latency above 800 ms, rolls back with no discussion." Deciding under stress, with the change author defending the change, goes badly.
- Make data changes reversible with expand and contract. Never rename or drop a column in the same release that stops using it. Expand: add the new column, write to both. Migrate: backfill old rows. Switch reads to the new column. Contract: drop the old one in a later release. Until the contract step, rolling back the code is safe.
Before and after
Weak plan:
Merge the migration and the new checkout code, deploy on Friday, watch the logs.
Better plan:
change: split checkout totals into tax_cents and net_cents
flag: checkout_split_totals # owner: payments, remove by 2027-02-01
stages:
- 1% of traffic, hold 30 min
- 25%, hold through the evening peak
- 100%
rollback_trigger: checkout 5xx > 1% for 5 min OR p95 > 800 ms
rollback: set flag to off (no deploy); old column is untouched
migration: add columns now, backfill, drop old column in a later release
What goes wrong
- The trigger is vague. "Roll back if it looks bad" lets everyone argue for twenty minutes while errors climb.
- The migration is one-way. Dropping a column makes the code rollback useless, because the old code needs it.
- The canary is too small to see anything. A 1% slice that never hits the failing path shows green. Pick a metric that the change can actually move.
- Flags never get removed. Old flags multiply code paths nobody tests.
Examples
A rollback trigger with numbers
The plan says: "Roll back if checkout 5xx stays above 1% for 5 minutes, or p95 latency exceeds 800 ms. The on-call engineer decides alone; no approval needed." At 14:07 the canary hits 2.3% errors. The on-call engineer flips the flag off at 14:09. Nobody debated, and the customer impact lasted two minutes.
Splitting a risky migration
An agent proposes one migration that renames total to total_cents and updates all queries. Reviewed into three releases: (1) add total_cents and write both columns, (2) backfill and switch reads, (3) drop total. Rolling back release 2 is safe because total still holds correct data.
Key points
- Separate deploying code from releasing it, so turning a flag off is the fastest rollback.
- Expand traffic in stages and hold each stage long enough to see a real peak.
- Write the rollback trigger with numbers before deploying, not during the incident.
- Use expand and contract so database changes stay reversible until a later cleanup release.
- Give every feature flag an owner and a removal date.
Common mistakes
- Writing the rollback trigger after the deploy, when the author is already invested in the change.
- Shipping a destructive migration in the same release as the code that stops using the old data.
- Judging the canary on a metric the change cannot affect, so it always looks green.
- Leaving flags in place for months, so nobody knows which code paths are live.
Check yourself · 2 of 3
When should the rollback trigger for a canary be decided?
Check yourself · 3 of 3
A change renames a database column. Which approach keeps rollback possible?
Practice items, not counted towards your mastery.
Start here
- Postmortem culture: learning from failure (Google SRE book) (opens in a new tab)BookFree
What a blameless postmortem is, what it contains, and how teams keep the habit alive.
- Incident response (Google SRE workbook) (opens in a new tab)BookFree
Worked incidents showing roles, handoffs and what a good response looks like in practice.
- Managing Incidents (Google SRE book) (opens in a new tab)BookFree
Incident command roles, a live incident document and clear handoffs.
More for this topic
- Feature Toggles (martinfowler.com) (opens in a new tab)ArticleFree
Kinds of toggles, how long they live, and how to keep them from piling up.
- Parallel Change (martinfowler.com) (opens in a new tab)ArticleFree
The expand, migrate, contract pattern behind reversible schema and API changes.
- Canarying releases (Google SRE Workbook) (opens in a new tab)BookFree
How to size a canary, pick metrics and decide to promote or roll back.