Topic 4 of 5 · 5 min read
Retraining, shadow tests and safe rollout
Goal: Plan a retrain-and-rollout for a model with a shadow test, promotion criteria and a rollback trigger.
Treat every new model as a release that must earn promotion: run it beside the current model first, decide in advance what counts as better, and keep a way back. A retrained model that scored well offline can still be worse in production.
Check yourself · 1 of 3
What is a shadow test?
Why it matters
Offline metrics use old data and a clean pipeline. Production has late events, odd inputs and feedback effects. A model that wins offline by a small margin may lose live, and an automatic "retrain and deploy" job can ship that loss without anyone looking.
When to retrain
- Scheduled: every week or month. Simple and predictable, but it may retrain when nothing changed or wait too long when something did.
- Triggered: when monitoring shows a quality drop or a strong drift with confirmed impact. It is more efficient but needs trustworthy monitoring.
- Many teams combine them: a regular schedule plus an early trigger.
Safe rollout, step by step
- Offline gate: the candidate must beat the current model on a fixed, recent test set, including key segments, not only the overall metric.
- Shadow test: the candidate receives live requests and logs predictions, but users only see the current model's output. You compare the two on real traffic with no user risk. Check latency, errors and score distribution.
- Canary: send a small share of traffic, for example 5 percent, to the candidate. Watch business and quality metrics.
- Promotion: raise traffic in stages if the pre-agreed criteria hold.
- Rollback: keep the previous model deployed and switch back if a trigger fires.
Write the criteria first
Before the test starts, write down promotion and rollback rules. For example:
promote_if:
shadow_days: 7
auc_vs_current: ">= -0.002"
p95_latency_ms: "<= 150"
segment_recall_drop: "<= 0.02"
rollback_if:
canary_error_rate: "> 1%"
canary_conversion_vs_control: "< -3%"
Deciding afterward invites picking the metric that happens to look good.
Before and after
Before: "The weekly job retrains and overwrites the model file." After: the job registers a candidate, runs it in shadow for seven days, and a person or a gate promotes it if the criteria pass, keeping last week's model one switch away.
What goes wrong
- Overwriting the production model with no previous version to return to.
- Judging only on overall accuracy while one customer segment gets worse.
- Ending a canary too early, before enough traffic has produced a reliable difference.
Examples
Shadow test catches a latency problem
A retrained ranking model scores higher offline. In a seven-day shadow run its 95th-percentile latency is 310 ms against a 150 ms budget, because a new feature needs a slow lookup. It is not promoted. The team caches the lookup and tries again, with no customer ever seeing the slow version.
Canary rollback
A candidate takes 5 percent of traffic. After two days, conversion in the canary group is 4 percent below the control group, which crosses the written rollback line of 3 percent. Traffic is switched back to the previous model within minutes, and the team investigates the segment that dropped.
Key points
- A retrained model is a release: it has to pass an offline gate, a shadow test and a canary before full traffic.
- Shadow mode runs the candidate on live requests while users see only the current model, so it carries no user risk.
- Write promotion and rollback criteria before the test starts, so the metric is not chosen after seeing results.
- Check key segments, latency and errors, not only one overall metric.
- Always keep the previous model deployed so rollback is a switch, not a rebuild.
Common mistakes
- Overwriting the live model file so the old version is gone.
- Deciding what counts as better after seeing the canary numbers.
- Promoting on an overall metric while a segment, such as new customers, gets worse.
- Automating retrain-and-deploy with no gate and no human-readable record of why it was promoted.
Check yourself · 2 of 3
When should promotion and rollback criteria be written?
Check yourself · 3 of 3
A weekly job retrains a fraud model and overwrites model.pkl in production. What is the main risk?
Practice items, not counted towards your mastery.
Start here
- Google: Rules of Machine Learning (opens in a new tab)ArticleFree
Practical rules from Google engineers on pipelines, monitoring, skew and launching models.
- Hidden Technical Debt in Machine Learning Systems (opens in a new tab)PaperFree
Why ML systems accumulate debt in data dependencies, glue code and feedback loops.
- MLflow documentation (opens in a new tab)DocsFree
How to log parameters, metrics, artefacts and model versions so runs can be compared and rebuilt.
More for this topic
- Continuous Delivery for Machine Learning (martinfowler.com) (opens in a new tab)ArticleFree
How to version data and models and automate testing and deployment of ML systems.