Testing in Production
ML Engineer path · lesson 76 of 80Offline evaluation cannot tell you a model works. Fan a request out to a shadow deployment, size an A/B test until the detectable lift shrinks, ramp a canary and abort it, redraw a team-draft interleaving list, and watch a bandit reach a verdict in 12,000 samples where A/B testing needed 630,000.
Name the technique
Sort each description into the testing-in-production technique.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
Shadow
Drop items hereA/B test
Drop items hereCanary
Drop items hereInterleaving
Drop items hereBandit
Drop items hereTest your knowledge
The book's distinction between monitoring and testing in production is that testing in production:
The short version
Tasting a new recipe. You can read it, you can cook it for yourself, and you can serve it to one table before you put it on the menu. Only the last one involves the people who will actually be eating it.
In more depth
Testing in Production
*"If monitoring means passively keeping track of the outputs of whatever model is being used, test in production means proactively choosing which model to produce outputs so that we can evaluate it."*
Why offline evaluation cannot finish
Static test splits must stay static — "it'll be hard to compare the test results of two models if they are tested on different test sets" — so a model updated for a new distribution should not be evaluated only on splits from the old one.
Backtests test "on data from a specific period of time in the past" — the last hour, after updating on the last day. But if a data pipeline bug corrupted the last hour's data, evaluating solely on it isn't sufficient, so the static set stays as a sanity check.
"The only way to know whether a model will do well in production is to deploy it."
Five techniques
Shadow deployment — "might be the safest way to deploy your model or any software update." Route each request to both, serve only the existing model's prediction, log the candidate's. Risk is low, but it doubles the number of predictions and generally doubles inference compute cost.
A/B testing — as of 2017, companies like Microsoft and Google each conduct over 10,000 A/B tests annually. Two things to get right: routing must be truly random (otherwise phone users on A, desktop users on B confounds everything) and enough samples. At p = 0.05, repeating the experiment gives "A is better" 95% of the time and "B is better" 5%. An insignificant result is not a failed test. When predictions affect each other — dynamic pricing changes how many drivers get on the road — run the variants alternately.
Canary release — "slowly rolling out the change to a small subset of users." You do not have to randomize the traffic; a plausible scenario is rolling out to a less critical market first.
Interleaving — Joachims, 2002. Netflix: it "reliably identifies the best algorithms with considerably smaller sample size compared to traditional A/B testing." Team-draft interleaving: for each position, pick A or B with equal probability, and that model takes its top item not already chosen. But "there's no guarantee that user preference will lead to better core metrics."
Bandits — ε-greedy, Thompson Sampling (1933), UCB (Auer, 2002), which "implements optimism in the face of uncertainty." Greg Rafferty: A/B testing needed over 630,000 samples for a 95% confidence interval; Thompson Sampling called a 5% improvement in under 12,000. A/B testing is stateless; bandits are stateful, which is why "bandit algorithms are not widely used in the industry other than at a few big tech companies."
Contextual bandits determine the payout of each action, not of each model. 1,000 items is a 1,000-arm problem where you see feedback only on the top 10 — the partial feedback problem, also known as bandit feedback. The trap: an item with 0 value points could be one that was never shown, so showing only high-value items keeps the same items on top forever.
Who runs the tests
Evaluation is usually owned by the same data scientists who developed the model, tested ad hoc. That is imbued with biases — "they probably won't use the model the way most users will" — and variable: "One data scientist might perform a set of tests and find that model A is better than model B, while another data scientist might report differently." The fix is clear, automated pipelines with promotion thresholds, reported and reviewed like CI/CD.
Interview Questions
References & Further Reading
Love this visualization?
Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.
100% free • No credit card required