Part IV — Expert Production Engineering · Chapter 20 · Lesson 2 of 7 · 5 min read
Lesson 2: Lifecycle States, Promotion, Canary Routing, and Rollback
Lesson level: Expert
Purpose: Move models from development to production through explicit, evidence-gated states, expose new versions to real traffic gradually, and return to a known-good version quickly when something goes wrong.
Learning objectives
By the end of this lesson you will be able to:
- define lifecycle states and the allowed transitions between them
- write promotion gates that require specific evidence
- compare shadow, canary, and champion-challenger rollouts
- route a deterministic share of traffic to a candidate model
- define automatic rollback triggers and execute a rollback
- record every transition with actor, reason, and evidence
2.1 Lifecycle states
| State | Meaning | Typical exit |
|---|---|---|
| Registered | Bundle verified and recorded; not yet reviewed | Submitted for review |
| Staging | Under evaluation in a production-like environment | Approved or rejected |
| Approved | Passed review; eligible for rollout | Canary started |
| Canary | Serving a small share of live traffic | Promoted or rolled back |
| Production (champion) | Serving the main traffic | Superseded or rolled back |
| Retired | No longer serving; kept for audit | Archived after retention |
| Rejected | Failed a gate | Archived |
Transitions are allowed only along defined edges. A model cannot jump from Registered to Production, and a Retired model cannot silently return; re-activating it is a new, recorded promotion with fresh evidence. Encode the state machine in the registry so that invalid transitions are refused rather than merely discouraged.
2.2 Promotion gates
A gate is a list of conditions, each tied to evidence stored in the bundle or registry. A typical gate into Approved requires:
- bundle verification passes and the manifest is signed (Lesson 6);
- the Chapter 19 acceptance tests pass on the release candidate;
- test metrics meet thresholds and beat the current champion on the primary metric by more than the bootstrap uncertainty, or match it with a documented other benefit;
- no segment falls below the fairness and performance limits (Lesson 4);
- the model card is complete and reviewed (Lesson 5);
- a named approver who is not the model author signs off.
Separation of duties matters: the person who trained the model should not be the only person who approves it.
2.3 Rollout strategies
| Strategy | How it works | Risk to users | What it proves |
|---|---|---|---|
| Shadow | Candidate scores every request; only the champion's result is used | None | Stability, latency, and agreement with champion |
| Canary | Candidate serves a small share (for example 5%), growing in steps | Limited to the canary share | Real outcomes and operational health |
| Champion-challenger | Long-running split for comparison of business outcomes | Limited to challenger share | Business impact over time |
A common sequence is shadow for a few days, then canary at 5%, 25%, and 50%, then full promotion — each step held long enough to observe the metrics that matter. For decisions whose outcomes take weeks to appear (churn, default), operational health is observable quickly but accuracy is not; plan the rollout around the slowest signal you need.
2.4 Deterministic routing
Route by a stable key, not at random per request. Hashing the customer ID into 100 buckets and sending buckets 0–4 to the canary means the same customer always sees the same model, which keeps experiences consistent, makes outcomes attributable, and allows exact replay.
Illustrative listing.
import hashlib
def bucket(key: str, salt: str = "churn-rollout-2026-11") -> int:
digest = hashlib.sha256(f"{salt}:{key}".encode()).hexdigest()
return int(digest[:8], 16) % 100
def choose_model(customer_id: str, canary_percent: int) -> str:
return "candidate" if bucket(customer_id) < canary_percent else "champion"
Change the salt for each new rollout so that the same customers are not always the guinea pigs. Log the chosen model with every prediction (Lesson 3).
2.5 Rollback
Rollback returns traffic to the last known-good version. It must be fast, rehearsed, and possible without retraining or rebuilding anything. Keep the previous champion bundle loaded or loadable, and make rollback a single registry transition that the serving layer observes (Chapter 21 covers graceful reloads).
Define automatic rollback triggers before the canary starts, for example:
- error rate or schema-rejection rate on the canary more than double the champion's over 15 minutes;
- p95 latency above the service objective for 10 minutes;
- prediction distribution shifting beyond a set divergence from the shadow baseline (Lesson 4);
- any integrity or signature verification failure.
Business-outcome regressions usually need human judgment because outcomes arrive slowly; define who decides and within what time. After any rollback, record the reason, keep the failed version in the registry as Rejected with its evidence, and hold a short review before a new attempt.
2.6 Recording transitions
Every state change is an append-only event: model and version, from-state, to-state, actor, timestamp (UTC), reason, and links to evidence. The current state is derived from the event history, never edited directly. This history is what an auditor reads to answer "who put this model into production, and on what basis?".
Common mistakes
- Direct deployment to production: skip no states; gates exist to catch what tests miss.
- Self-approval: require a second person for promotion.
- Random per-request routing: customers flip between models and outcomes cannot be attributed.
- Undefined rollback triggers: agree on them before the canary, not during an incident.
- Rollback that needs a rebuild: keep the previous champion ready to serve.
- Editing state without events: the audit trail becomes fiction.
Guided practice
- Draw the lifecycle state machine and list the allowed transitions.
- Compute canary buckets for 1,000 synthetic IDs at 5% and confirm the share and stability across reruns.
- Write rollback triggers for a fraud model where outcomes arrive after 30 days.
Hands-on lab: A gated rollout
- Implement the lifecycle state machine in the file-backed registry, refusing invalid transitions.
- Write a promotion gate for Approved that checks verification, test results, metric comparison, model card presence, and a second approver.
- Run version 1.1.0 of the churn model in shadow against 1.0.0 on replayed traffic and report agreement and latency.
- Start a 5% canary with deterministic routing; inject a schema-rejection spike and confirm the automatic rollback fires.
- Produce the event history for the whole exercise.
Review questions
- Why must lifecycle transitions follow defined edges?
- What evidence should a promotion gate require?
- How do shadow and canary rollouts differ in risk and in what they prove?
- Why route by a hashed stable key?
- What makes a rollback fast and safe?
- Why is the current state derived from events rather than stored directly?
Applied challenge
A pricing model affects revenue immediately, and a bad version could cost significant margin in hours. Design its lifecycle, gates, rollout plan with step sizes and hold times, automatic and human rollback triggers, and the on-call runbook for rollback.
Lesson summary
Lifecycle states with evidence-gated, separately approved transitions turn promotion into a controlled process. Shadow and canary rollouts expose new versions gradually with deterministic routing, predefined triggers make rollback fast, and an append-only event history records who did what and why.
Lesson status: Ready for review.