PeaBox Lab › PeaLang › Learn › Chapter 20 › Lesson 2

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:

2.1 Lifecycle states

StateMeaningTypical exit
RegisteredBundle verified and recorded; not yet reviewedSubmitted for review
StagingUnder evaluation in a production-like environmentApproved or rejected
ApprovedPassed review; eligible for rolloutCanary started
CanaryServing a small share of live trafficPromoted or rolled back
Production (champion)Serving the main trafficSuperseded or rolled back
RetiredNo longer serving; kept for auditArchived after retention
RejectedFailed a gateArchived

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:

Separation of duties matters: the person who trained the model should not be the only person who approves it.

2.3 Rollout strategies

StrategyHow it worksRisk to usersWhat it proves
ShadowCandidate scores every request; only the champion's result is usedNoneStability, latency, and agreement with champion
CanaryCandidate serves a small share (for example 5%), growing in stepsLimited to the canary shareReal outcomes and operational health
Champion-challengerLong-running split for comparison of business outcomesLimited to challenger shareBusiness 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:

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

Guided practice

Hands-on lab: A gated rollout

Review questions

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.

← Previous Next →