Sub topic 15
Safe Rollout: Shadow, Canary, and Rollback
Assume you know how to train, evaluate, and deploy a model, and that a serving system can route requests to more than one model version. This chapter focuses on reducing risk after the evaluation gate approves a challenger.
A good offline score does not prove that a model is safe in production. Real traffic can contain unseen values, delayed labels, unexpected load, or a change in user behavior. A rollout makes the new model observable before it receives full responsibility.
Shadow deployment
In a shadow deployment, the current champion handles the real request and response. The challenger receives a copy of the request and produces a prediction, but its prediction is not returned to the user or used to make a business decision.
Log both predictions and compare them. Useful signals include:
- Prediction disagreement rate.
- Latency and error rate.
- Input validation failures.
- Resource use.
- Differences for important user or data segments.
Shadow mode is useful when labels arrive later. It lets you measure operational behavior immediately, then compare predictions with outcomes when labels become available.
Canary deployment
A canary rollout sends a small percentage of live traffic to the challenger. For example, route 1% of requests to it while the champion serves the remaining 99%. Increase the percentage only when predefined checks pass.
Monitor both technical and business metrics:
| Signal | Example guardrail | Action |
|---|---|---|
| Error rate | Challenger is no more than 0.2 percentage points worse | Stop or roll back |
| P95 latency | Less than 150 ms | Stop or roll back |
| Business metric | No material regression | Continue cautiously |
Keep traffic assignment stable when possible. Sending the same user to different versions can make experiments difficult to interpret. Compare equivalent time windows and segments rather than relying on a single aggregate average.
from dataclasses import dataclass
@dataclass(frozen=True)
class RolloutMetrics:
challenger_error_rate: float
champion_error_rate: float
challenger_p95_ms: float
business_regression: float
def canary_is_safe(metrics: RolloutMetrics) -> tuple[bool, str]:
error_delta = metrics.challenger_error_rate - metrics.champion_error_rate
if error_delta > 0.002:
return False, "error_rate_regression"
if metrics.challenger_p95_ms > 150:
return False, "latency_limit_exceeded"
if metrics.business_regression > 0.01:
return False, "business_regression"
return True, "increase_traffic"
print(canary_is_safe(RolloutMetrics(0.011, 0.010, 120, 0.002)))Rollback and release criteria
Define rollback before deployment. A rollback should restore the last known-good model and configuration, not retrain immediately. Keep the champion artifact available, retain its dependencies, and make the routing change reversible.
Use a staged policy such as:
- Run shadow evaluation.
- Start at 1% canary traffic.
- Increase to 10%, 25%, and 50% after observation windows pass.
- Promote fully only when technical and business checks pass.
- Roll back automatically on severe guardrail violations.
- Investigate the failed challenger before trying again.
Exercise
Why can shadow deployment reveal latency problems but not prove that a challenger improves business outcomes immediately?
Show answer
Shadow traffic measures operational behavior immediately, but business outcomes usually require labels or later user outcomes that arrive after the prediction.