Interview's MateData Science
Interview's Mate

Data Science

Python → ML → MLOps

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Science topics
Lesson 158/ 160
08. MLOps & Model Deployment

Shadow Deployment & Canary Rollouts

Roll out new models safely with shadow traffic and gradual canary percentages.

AdvancedShadow · Canary3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Instead of switching everyone to a new model at once, you let it quietly make predictions on the side, then try it on a few users, and only roll it out to everyone if all looks good.

Think of it like…

Introducing a new recipe at a restaurant. First the chef cooks it in the back for staff to taste (shadow), then offers it to a few tables (canary) while watching reactions, and only if diners are happy does it replace the old dish on the whole menu; if anyone gets ill, the old recipe returns immediately.

Where you’ve seen it

The candidate churn model v12 first runs in shadow: every scoring request is mirrored to v12 asynchronously, results go to a log table and latency never affects the response. Over 100,000 requests the two models agree on the contact/no-contact decision for 97.2%; the 2,800 disagreements (2.8%) are mostly customers near the threshold, and a reviewer inspects a random sample of 200 and finds no systematic problem. v12's p95 latency is 41 ms against the champion's 38 ms and the score distribution has PSI 0.04 against the champion's, so it passes the shadow checklist. The canary then assigns traffic by hashing the customer ID (hash(customer_id) % 100 < 5) so each customer consistently sees one model. Stage 1 sends 1% for at least an hour and checks only health (error rate below 1%, p95 under 60 ms, no null scores); stage 2 sends 5% for three days. Why three days? To detect a one-point difference in a 10% conversion rate with 80% power at the 5% level, Lehr's rule gives roughly n = 16 × p(1 − p) / δ² = 16 × 0.09 / 0.0001 = 14,400 per arm. At 100,000 requests a day the 5% canary gets 5,000 a day, so reaching 14,400 takes about 2.9 days. The blast radius at 5% is 5,000 requests a day, so even a bad model affects few customers. Because churn labels take 30 days, the canary can't prove retention outcomes; it checks leading indicators (decision rates, offer acceptance in the first week, latency, score drift), and a randomised holdout continues in the background so the final verdict arrives when labels mature. Automatic rollback triggers are defined up front: error rate above 1%, p95 above 60 ms for 10 minutes, score PSI above 0.1 against shadow expectations or a significant drop in the proxy KPI; rollback is the alias change from the registry lesson, taking about a minute. Stages 25% and 100% follow if guardrails hold; the champion alias moves only at the end, and v11 stays loadable for a week. Shadow runs, canary stages, decisions and thresholds are written to the release record so the next model follows the same playbook.

Words you’ll hear

Shadow deployment
Running a candidate on mirrored traffic without returning its output to users.
Canary
Serving a small share of real traffic with the new model while monitoring guardrails.
Sticky assignment
Routing the same user or entity to the same model each time, usually by hashing an ID.
Blast radius
The number of users or requests affected if the release is bad.

Visual diagram

Loading interactive diagram

Theory & deep dive

Shadow deployments and what to compare

In shadow mode the candidate scores a copy of each production request, asynchronously, and its predictions are stored with the champion's but never returned. Because users see nothing, you can run it on 100% of traffic and learn about behaviour on real inputs: crashes and null outputs, latency (p95 41 ms against 38 ms), agreement with the champion (97.2% of decisions in the example) and the score distribution (PSI 0.04). Inspect the disagreements (2,800 per 100,000): they concentrate near the decision threshold, and reviewing a random sample of 200 shows whether the candidate's choices are plausible. You can also replay logged traffic offline against the candidate, and join labels as they mature to compute performance for both models on the same cases.

Shadow has limits. It cannot show user reactions (the candidate's decisions weren't acted on), so behavioural metrics (conversion, acceptance) are unavailable, and it doesn't reveal feedback effects where the model's decisions change future data. It also costs extra compute and must not affect production latency, so mirror asynchronously with a bounded queue and drop mirrored requests under load. Treat shadow as the screening stage: its job is to catch problems cheaply, not to prove the candidate is better.

Shadow report

100,000 mirrored requests. Errors: 0. Null scores: 0. p95: 41 ms vs 38 ms. Decision agreement: 97,200 (97.2%); disagreements 2,800, of which 71% within ±0.05 of the threshold. Score PSI vs champion: 0.04. Reviewed sample of 200 disagreements: no systematic issue. Verdict: pass to canary.

Key takeaway: Use shadow to compare behaviour, latency and decisions on real inputs without risk, but don't mistake it for proof of better outcomes.

Canary rollouts, power and guardrails

A canary gives the candidate a small share of real decisions. Route by hashing a stable ID (hash(customer_id) % 100 < 5) so each entity consistently gets the same model, which avoids flip-flopping experiences and contamination. Advance through stages, for example 1% for an hour (health only), 5% for several days (outcome proxies), 25% and 100%, with explicit guardrails and an automatic rollback: error rate above 1%, p95 above 60 ms for 10 minutes, score distribution shift (PSI above 0.1) or a significant drop in the proxy KPI. Rollback is an alias change in the registry, taking about a minute. The blast radius is the exposed share: at 5% of 100,000 requests a day, a bad model touches 5,000 requests a day.

Plan statistical power so you don't declare victory (or failure) on noise. To detect a 1-point difference (δ = 0.01) in a 10% rate with about 80% power at the 5% level, Lehr's rule gives n ≈ 16 p(1 − p) / δ² = 16 × 0.09 / 0.0001 = 14,400 per arm. At 5,000 canary requests a day that takes 14,400 / 5,000 ≈ 2.9 days, so the 5% stage runs about three days; a smaller effect needs a much longer stage (halving δ quadruples n). When labels are delayed (30 days for churn), the canary checks leading indicators and operational guardrails, while a small randomised holdout keeps running until outcomes mature. For decisions where the model drives actions, distinguish a canary (is it safe?) from an A/B test (does it improve a business metric?), and pre-register the metric, sample size and stopping rule to avoid peeking.

Sample-size arithmetic

Baseline rate p = 0.10, detect δ = 0.01. n ≈ 16 × 0.10 × 0.90 / 0.01² = 16 × 0.09 / 0.0001 = 14,400 per arm. Canary 5% of 100,000/day = 5,000/day → 2.9 days. For δ = 0.005: n = 57,600 → 11.5 days.

Key takeaway: Size each stage from the effect you need to detect, route stickily and define automatic guardrails and rollback before starting.

How it works, step by step

Step 1 of 4
ML engineer

1. Mirror traffic in shadow

Send a copy of requests to the candidate asynchronously, log both outputs and compare errors, latency and decisions.

agree 97.2% · p95 41 vs 38 ms
Key numbers at this step
Review
200 disagreements

When to use it & trade-offs

What it is

Rolling out a new model safely uses two complementary techniques. In a shadow deployment the candidate receives a copy of live traffic and produces predictions that are logged but never shown to users, so you can compare it with the champion on real inputs with zero customer risk. In a canary rollout the candidate serves a small, sticky percentage of real traffic (1%, then 5%, 25%, 100%) while guardrail metrics are watched, and the rollout advances or rolls back automatically. Related patterns are A/B tests (a controlled experiment designed to measure impact with statistical power) and blue-green deployments (two full environments with a traffic switch). For ML the crucial complication is delayed or missing labels: you often can't tell whether the candidate is better for weeks, so rollouts rely on proxies, offline replay and carefully sized experiments.

Why it matters: Offline evaluation can't capture everything: production traffic has edge cases, latency characteristics and feedback effects that a holdout set lacks. A bad model released to everyone at once can cost revenue or harm customers before anyone notices. Gradual exposure limits the blast radius, shadow mode catches crashes and gross disagreements for free and statistical planning ensures that you wait long enough to see real differences rather than noise.

When to reach for it

  • Shadow before any customer-facing model change
  • Canaries with sticky routing and automatic rollback
  • Randomised holdouts to confirm delayed-label outcomes

When to avoid or be careful

  • Switching all traffic at once on offline metrics alone
  • Declaring a canary a win without sample-size planning
  • Random per-request routing that flips a user between models

Release strategies

Shadow deployment
Best for: Checking behaviour and latency on real inputs with no user risk

Strengths: Safe; full traffic; enables decision comparison.

Watch out: No user-behaviour or outcome signal.

Canary rollout
Best for: Gradual exposure with guardrails and fast rollback

Strengths: Limits blast radius; catches real-world issues.

Watch out: Slow to prove outcomes with delayed labels.

A/B test
Best for: Measuring the business impact of a change

Strengths: Causal estimate with controlled design.

Watch out: Needs sample size, time and discipline.

Blue-green switch
Best for: Instant switch and rollback of a whole environment

Strengths: Fast rollback.

Watch out: Doubles capacity; all users switch at once.

Interview signals & numbers to know

When this topic comes up

  • “How would you roll out a new model?”
  • Shadow versus canary versus A/B
  • Sample size for a canary
  • Handling delayed labels during rollout
  • Rollback triggers

Benchmarks & rules of thumb

97.2% agreement -
decisions matched in the shadow example
14,400 per arm -
16 × 0.09 / 0.01² to detect a 1-point change in a 10% rate
≈ 2.9 days -
time to fill 14,400 at 5,000 canary requests a day

Common mistakes & follow-ups

Common interview mistakes

  • Letting the shadow call slow the live response.
  • Ending a canary after a day because nothing looked wrong.
  • Leaving no automatic rollback path.

Likely interviewer follow-ups

  • How would you canary a model whose labels arrive in 90 days?
  • What guardrails would you set for a fraud model?
  • How do you avoid peeking at A/B results?
Interview tip: Do the sample-size arithmetic aloud; it turns a canary from a ritual into an experiment.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Shadow Deployment & Canary Rollouts with data science interview Q&A and hands-on practice.

Open Data Science Q&A →Machine Learning Q&A
Previous topic
Automated Retraining Pipelines
Next topic
Fairness, Bias Auditing & Responsible AI