Sub topic 15
Safe rollout: shadow, canary, and rollback
A challenger model that passes the evaluation gate has only been tested on historical data. Live traffic can still expose problems: a feature that is computed differently online, a latency spike, or a segment of users the offline set underrepresented. This chapter covers how to expose a promoted model to production gradually, and how to undo that exposure quickly.
This chapter assumes you know the stages of a retraining pipeline, the champion and challenger terms from the evaluation gate, and how a model registry stores versions. You should also be comfortable with batch or online serving.
Why offline evaluation is not enough
Offline evaluation answers "was this model good on data we already have?" Rollout answers "does this model behave well in the real serving path, on data arriving right now?" The two differ in several ways:
- Training-serving skew. Features computed in the batch pipeline may differ from features computed by the online service. The offline AUC will not show this.
- Operational behavior. Latency, memory use, timeouts, and error rates only appear when the model runs in the serving stack.
- Feedback effects. If model outputs change what users see, the data you later collect changes too. A static test set cannot capture this.
- Rare segments. A small drop on a segment that is 2% of traffic can hide inside a healthy overall metric.
Rollout is therefore a second gate, run on live traffic with a limited blast radius.
Three deployment patterns
| Pattern | Does the challenger affect users? | What it tells you | Main cost |
|---|---|---|---|
| Shadow | No | Prediction differences, latency, errors | Double inference compute |
| Canary | Yes, for a small share | Real outcome metrics and operational health | Some users get a possibly worse model |
| Full rollout | Yes, for everyone | Nothing new; this is the end state | Largest blast radius |
Shadow deployment
In a shadow deployment, the serving layer sends each request to the champion and also to the challenger. Only the champion's response is returned. The challenger's response is logged and compared.
Shadow mode is the safest option because users never see the challenger's output. It is good at catching crashes, schema mismatches, latency problems, and large disagreements between the two models. It cannot measure outcomes that depend on the user acting on the prediction, because no user acted on it.
Two practical details matter. First, the challenger call must be asynchronous or time-limited so that a slow challenger cannot slow down the champion's response. Second, log both predictions with a shared request ID so you can join them later with labels.
Canary deployment
In a canary deployment, a small share of real traffic, such as 1% to 5%, receives the challenger's predictions. You watch metrics for the canary group and compare them with the champion group. If they hold, you raise the share in steps.
Route by a stable hash of a user or entity ID, not by random choice per request. Otherwise one user can bounce between models within a session, which confuses both the user and your analysis.
Deciding when to advance
Each stage needs explicit pass criteria written before the rollout starts. Typical checks fall into three groups:
- Operational health: error rate, p95 latency, and timeout rate stay within a fixed margin of the champion.
- Prediction sanity: the score distribution of the challenger is close to the champion's, and the fraction of extreme or missing outputs has not jumped.
- Outcome metrics: business or quality metrics, when labels or proxies are available, are not worse than the champion beyond a tolerance.
Outcome metrics bring back the label delay problem. If labels arrive in 30 days, a canary cannot confirm quality within an hour. In that case, use fast proxies (click-through, early repayment signals, human review of a sample) for the early stages, and keep the canary running long enough to collect real labels before you go to full traffic. State clearly which metrics gate which stage.
Each stage also needs a minimum number of requests. A 5% canary that has handled 40 requests proves nothing. Require both a minimum duration and a minimum sample size.
A canary decision function
The function below compares canary and champion metrics and returns an action with a reason. It follows the same style as the evaluation gate: simple, explicit, and testable.
from dataclasses import dataclass
@dataclass(frozen=True)
class CanaryConfig:
min_requests: int = 5_000
max_error_rate_increase: float = 0.002
max_p95_latency_ratio: float = 1.2
max_metric_drop: float = 0.01
def canary_decision(canary, champion, cfg):
"""Return (action, reason). Action is 'wait', 'advance', or 'rollback'."""
if canary["error_rate"] - champion["error_rate"] > cfg.max_error_rate_increase:
return "rollback", "error_rate"
if canary["p95_ms"] > champion["p95_ms"] * cfg.max_p95_latency_ratio:
return "rollback", "latency"
if champion["metric"] - canary["metric"] > cfg.max_metric_drop:
return "rollback", "quality_drop"
if canary["requests"] < cfg.min_requests:
return "wait", "not_enough_traffic"
return "advance", "healthy"
champion = {"error_rate": 0.001, "p95_ms": 80, "metric": 0.91, "requests": 95_000}
canary = {"error_rate": 0.001, "p95_ms": 85, "metric": 0.91, "requests": 6_000}
print(canary_decision(canary, champion, CanaryConfig()))
slow = dict(canary, p95_ms=140)
print(canary_decision(slow, champion, CanaryConfig()))Notice the order. Hard failures such as errors and latency trigger a rollback even when the sample is small, because waiting for more traffic would only expose more users to a broken model. Only the "advance" decision requires enough data.
Rollback
Rollback is the act of returning traffic to the previous champion. It only works if you prepared for it.
- Keep the previous model deployable. The old version stays in the registry with its artifacts, its feature code version, and its serving configuration. Do not delete it when the new one is promoted.
- Make rollback a routing change. The fastest rollback flips a pointer, such as a registry alias or traffic weight, and does not require a rebuild. Aim for minutes or less.
- Automate the hard triggers. Error rate and latency breaches should roll back without waiting for a person. Quality-based rollbacks can page a human first.
- Record the event. Log which version was rolled back, why, and which metric breached. The trigger policy should read this record.
That last point connects to the retraining loop. If a challenger is rolled back, the pipeline must not immediately retrain and redeploy a near-identical model. Treat a rollback as a signal: start a cooldown, mark the data snapshot or code version as suspect, and require a person to review before the next attempt.
Rollback and stateful side effects
Rollback is simple when the model is stateless. It is harder when the model's outputs were written somewhere. Cached predictions, precomputed recommendations, and downstream features derived from the challenger's scores can all outlive the rollback. Decide in advance which of these must be invalidated, and tag stored predictions with the model version so you can find and purge them.
Common errors
- Canary and champion see different traffic. If the canary is routed by region or time of day, differences in metrics may come from the population and not from the model. Randomize by hashed ID within the same traffic pool.
- Comparing against a stale baseline. Compare the canary with the champion measured at the same time, not with last month's numbers.
- No pass criteria until after the fact. Thresholds chosen after seeing results tend to justify whatever happened.
- Rolling back the model but not the feature code. If the retrained model needed a new feature version, the old model may break on it. Version them together.
- Shadow mode that quietly drops the challenger's errors. Count and alert on shadow failures too. A challenger that crashes on 3% of requests in shadow will crash on 3% in production.
Exercise
Your canary receives 5% of traffic. After two hours, error rate and latency match the champion, but only 120 labeled outcomes have arrived and the canary metric is 0.03 lower than the champion's. What should the decision function do, and why?
Show answer
It should not roll back on quality alone yet, and it should not advance. With only 120 labeled outcomes, a 0.03 difference may be noise, so the right action is to wait while operational checks keep running. Add a minimum labeled-sample requirement (or a confidence interval on the difference) to the quality check. If the gap persists once enough labels arrive, roll back.
Exercise
Why should a canary route users by a hash of their ID and not by choosing the model randomly for each request?
Show answer
Hash routing keeps each user on one model for the whole canary. Per-request random routing can switch a user between models mid-session, which makes the experience inconsistent and makes per-user metrics impossible to attribute to one model.