learn-ml-production-with-phoebe / Session 3 of 6
ML in Production: The Leader Cut · Session 3 of 6

Shadow, canary, or all at once

The model has cleared its baseline and the team wants to ship. The question in front of the leader is not "is it good enough?" any more; that was session 2. It is "how does it meet real traffic, how much of the decision does it get to make, and how fast can we take it back?" Tonight is three decisions in that order: the degree of automation, the deployment pattern, and the rollback. You leave with a one-page rollout plan for a model you are about to ship, with a promotion gate between every stage and a rollback somebody has actually timed.

🟠 Advanced Leaders who sign off a rollout Builders who run the switch 45 min
0-3 · Welcome 3-18 · Automation, patterns, rollback 18-40 · Build-along: the rollout plan 40-45 · Q&A
Part 0

Where we start

Most launch reviews argue about the model's accuracy and wave the rollout through as an engineering detail. It is the other way round. Accuracy was measured on yesterday's data, offline. The rollout is the first time the model sees today's inputs, computed by today's pipeline, and the first time anyone acts on what it says. How that first contact is staged decides how much a mistake costs, how quickly you find it, and whether finding it means an apology or a one-line switch.

🎫 Clear all three quiz questions to stamp your passport Live = presented in the 45 minutes Self-study = the full depth, after class ★ Build-along = fill it in for your own system

★ What you walk out with tonight. A one-page rollout plan for one model: the degree of automation it starts at and the one it should stop at, the deployment pattern and the reason for it, each stage with its traffic share and its promotion gate, the skew check that runs during shadow, and a rollback with a trigger, an owner, a time and the date it was last rehearsed.

Part 1 · covers Ng's degrees of automation

How much of the decision does the model make?

5 min live

Before choosing how to deploy, decide what the model is for once it is deployed. Andrew Ng's Machine Learning in Production lectures lay out five degrees of automation, from a human deciding everything to the model deciding everything (reported, from compiled lecture notes). The two steps in the middle keep a human in the loop. The decision a leader signs here is not "do we automate?" but "which step do we aim for, and which step do we stop at?"

FIVE DEGREES OF AUTOMATION: WHO MAKES THE CALL AT EACH STEP left to right, the model makes more of the decision human in the loop human only human decides every case shadow mode model runs too output logged only AI assistance model suggests human decides all partial automation sure: model decides unsure: a human full automation model decides all human audits Steps as named in Ng's lectures (reported). Ochre: the step most projects should aim for first.
🔍 Click to zoom - you choose the step you stop at; full automation is one option, not the destination
LiveThe five steps, and what the human does at each2 min▶
StepWho decidesWhat the human does
Human onlyA person, every caseEverything. This is today's process and the baseline the model has to beat
Shadow modeStill the personWorks exactly as before; the model runs alongside, and its output is logged, never shown or used
AI assistanceThe person, with a suggestionSees the model's answer and decides; the model speeds the person up
Partial automationThe model when it is confident, the person otherwiseTakes the cases the model is unsure about
Full automationThe model, every caseAudits samples, handles complaints, owns the off switch

Ng's lectures call the two middle steps "human in the loop" (reported). They are where most of the value sits for the fewest surprises: the model does the easy, confident volume, and people keep the cases where a wrong answer costs the most.

LiveChoose the step by the cost of an error and how often the model is sure2 min▶

Two numbers pick the step. The first is the cost of one wrong decision acted on without a person checking it. The second is the share of cases where the model is confident enough to be trusted alone, measured on your data, not assumed. A high error cost and a small confident share point to AI assistance. A moderate cost and a large confident share point to partial automation. Full automation needs a low error cost, or a confident share so large and so well measured that the remaining human review would add nothing.

You can stop at any step. Full automation is not the goal by default; for many decisions partial automation is the finished product, because the human queue is exactly where the expensive errors would have gone. Write the stopping step into the plan now, so that "let's automate the rest" becomes a new decision later rather than a drift.

Self-studyMove up one step at a time, each with a promotion criterion2 min▶

Each step up is its own launch. Give every move a written criterion before it happens: shadow to assistance when the model agrees with the human on enough cases and its disagreements are reviewed; assistance to partial when the people using it accept its confident answers almost always and the confidence threshold has been set on logged data; partial to full only if the human queue has stopped catching anything the model got wrong. The thresholds are yours to set and they will differ by decision. What must not differ is that each one is written before the move, not argued after it.

Real world

A model that watches the inspector first. Ng's own example of shadow mode is a visual inspection system on a production line (reported, from compiled lecture notes). A human inspector keeps checking parts as before. The model runs in parallel on the same parts, and its verdicts are logged and not used for anything. Only when the logged verdicts are compared with the inspector's and found good enough does the model get to influence a decision at all. The leader's signature at this step costs almost nothing: no customer ever sees a shadow prediction.

Part 2 · covers Ng's deployment patterns

Three ways to meet real traffic

6 min live

Once the step is chosen, the deployment pattern decides how traffic reaches the new model. Ng's lectures teach three (reported). Shadow mode copies every request to the new model and serves the old answer. A canary sends a small share of traffic to the new model, "maybe 5% (or even less of traffic initially)", and the rest to the old one. Blue-green keeps two full stacks and switches between them, which makes rollback easy. The decision here is which risk you are buying down: not knowing, blast radius, or time to undo.

WHERE EACH REQUEST GOES, AND WHOSE ANSWER THE CUSTOMER GETS SHADOW CANARY BLUE-GREEN request every request copied old model new model answer served logged, not served request router the rest "maybe 5%" old model new model both served, both monitored request one switch blue: old stack green: new stack kept warm serving now Patterns and the canary share as in Ng's lectures (reported). Dashed: traffic that is not served to anyone.
🔍 Click to zoom - shadow buys knowledge, canary limits the blast radius, blue-green buys time to undo
LiveShadow: what it proves, and what it cannot2 min▶

A shadow run puts the new model on real inputs, computed by the real serving pipeline, at real load. It proves three things cheaply: whether the features it sees live match the ones it was trained on (training/serving skew, Part 3), how often it agrees with the old model or the human, and whether it meets its latency budget under real traffic. Nobody is affected if it is wrong.

What it cannot prove is the effect of acting on its predictions. Its answers are never used, so the world never reacts to them: no customer changes behaviour, no downstream team works a different queue, no feedback loop starts. If the value of the model depends on what happens after the decision, shadow mode tells you nothing about that value. Only live traffic does, which is what the canary is for.

LiveCanary: what it limits, and the rule you need before it starts2 min▶

A canary limits the blast radius. If the new model is wrong in a way shadow could not show, only the small share of traffic routed to it is hurt, and for only as long as the canary runs. It also gives you the first measurement of the model's real effect, on a sample, with the old model serving the rest as a live comparison.

The canary is only as good as the promotion rule written before it starts: the metrics the new model must clear against the old one on the same period, the minimum duration or volume before anyone looks, and the result that sends it back. A canary without that rule becomes a slow full launch, promoted because nothing loud went wrong.

LiveBlue-green: instant rollback, and what it costs1 min▶

Blue-green runs two complete serving stacks. All traffic goes to one; the switch moves it to the other. The old stack stays warm, so rolling back is one switch, not a redeploy. The price is running two full stacks for as long as you want that option, and the discipline to keep the old stack truly deployable: same feature pipeline, same dependencies, still passing its checks. A blue stack that quietly rotted is not a rollback.

Self-study"All at once" is a legitimate choice, sometimes2 min▶

Switching all traffic in one move is not reckless by definition. It is the right call when a wrong prediction is cheap and reversible (a ranking tweak, an internal dashboard, a recommendation a person glances past), when traffic is too thin for a small share to tell you anything in a useful time, and when the old model can be restored quickly by redeploying it. What makes it safe is not the pattern; it is a rollback plan that exists before the switch, a monitor that would notice the problem, and an owner who is on call the day it ships.

Real world

Even at Google, these are not a given. The ML Test Score paper lists a canary test and a rollback test among its 28 production tests, and reports what its authors found when they met 36 teams across Google: "none of these tests was implemented by more than 80% of teams". Staged rollout and quick rollback sound like hygiene. In practice, at one of the most mature ML organisations there is, some teams did not have them. A leader should ask for them by name rather than assume them.

Part 3 · covers rollback and training/serving skew

Write the rollback before the rollout

4 min live

The pattern follows from three questions, asked in order. The first is whether a person makes this decision today, because if one does, shadow mode is almost free and you should take it. The rest is about what a mistake costs and how fast you must undo it. Whatever the answer, the plan has one line that is not optional: how you roll back, who pulls it, and how long it takes.

THREE QUESTIONS, IN ORDER, PICK THE PATTERN Q1 · does a human make this decision today? Q2 · is one wrong prediction expensive? Q3 · do you need rollback in seconds? start in shadow mode canary, small share blue-green all at once, with a rollback plan the human is a free comparison limit the blast radius two stacks, one switch yes yes yes no no no every branch has one The patterns are Ng's (reported); the order of the questions is a teaching aid, not a rule from the lectures.
🔍 Click to zoom - shadow first whenever a person already makes the call; a canary is shadow's next step, not its replacement
LiveRollback has to be rehearsed, not just possible2 min▶

The ML Test Score puts rollout and rollback in its infrastructure section. Infra 6 is the canary test. Infra 7 reads: "Models can be quickly and safely rolled back to a previous serving version." Both halves of that sentence are tests a team can fail. "Quickly" means somebody has timed it. "Safely" means the previous version still works with today's feature pipeline and today's dependencies, which you only know if you tried.

A rollback nobody has run is a hope. Rehearse it on a quiet day, time it, and write down who can pull it without asking anyone. In the ML Test Score's scoring, a rollback done by hand and documented earns half a point; one that runs automatically and repeatedly earns the full point.

LiveTraining/serving skew, and why shadow is the cheapest place to catch it2 min▶

Monitoring test 3 of the ML Test Score is "training and serving are not skewed": the features the model sees live are computed the same way as the features it was trained on. Among the 36 Google teams the authors met, they call it "Perhaps the most important and least implemented test". It is common because the same feature is usually computed twice, once in a batch pipeline for training and once in the serving path, by different code, sometimes by different teams.

Shadow mode is the cheapest place to catch it. The model is running on live inputs, nobody is acting on its output, and you can recompute the training-pipeline version of every served feature on the same rows and compare. Skew found in shadow costs a fix. Skew found in a full launch costs the decisions made on it. Statistical drift tests on the live inputs belong to Model Evaluation b9 ↗.

Self-studyZinkevich's three rules against skew3 min▶

Martin Zinkevich's Rules of Machine Learning spend three rules on the problem. Rule 29: save the features as they were at serving time and log them, so the model can be trained on exactly what it saw. Rule 32: re-use code between the training pipeline and the serving path, so there is one computation of each feature, not two. Rule 37, "Measure Training/Serving Skew": compare how the model performs on the data it was trained on, on held-out data, on next-day data and live. A gap between next-day data and live data "probably indicates an engineering error", because those should behave the same if the pipelines agree.

Rules 29 and 32 prevent skew; Rule 37 detects what gets through. A rollout plan should say which of the three you have.

Real world

The test most teams skip is the one that bites at launch. Of the 28 tests in the ML Test Score, the authors single out one after meeting 36 Google teams: training/serving skew, "Perhaps the most important and least implemented test". Zinkevich gives the practical tell in Rule 37: when a model does well on next-day data and worse live, the likeliest cause is not the world, it is an engineering error between two pipelines. Both come from people who ran production ML at scale, and both point at the same thing a shadow run can show before anyone is affected.

Build-along

The rollout plan

★ 22 min · everyone builds

Pick one model that is about to ship, or one that shipped all at once and should not have. If you have none, use the Elec2 price-direction model from session 4. Six blocks, each copied into a document and filled in. The plan is finished when a person who was not in the room could run the rollout and the rollback from it.

THE PLAN AS A TIMELINE: STAGES, GATES, AND A WAY BACK FROM EVERY ONE a gate: the new model clears the written numbers, or it stays where it is gate gate gate gate shadow 0% served 2 weeks canary 1 "maybe 5%" 1 week canary 2 25% 1 week canary 3 50% 3 days full 100% old kept warm rollback old model: still deployed, one switch away Only "maybe 5%" is Ng's (reported). Every other share and duration is constructed; your numbers will differ.
🔍 Click to zoom - every stage has a gate forward and an arrow back; a plan missing either is a launch, not a rollout

Name the step you start at and the step you stop at. From Part 1. The stopping step is the one that tends to go unwritten, and it is the one that stops "just automate the rest" from happening by drift.

★ Block 1 · degree of automationModel: ____________________________ Today the decision is: human only / shadow / assistance / partial / full We start at: ____________ We aim for: ____________ and we stop there unless: ____________ Confident share needed for partial automation: ____ (measured on logged data)

Pick the pattern by answering the three questions. Write the answers, not only the result. If the answer to Q1 is yes, the plan starts in shadow, whatever comes after.

★ Block 2 · the pattern and whyQ1 Does a human make this decision today? yes / no Q2 Is one wrong prediction expensive? yes / no (cost of one: ________) Q3 Do we need rollback in seconds? yes / no Pattern: shadow -> canary / canary / blue-green / all at once Because: ______________________________________________

Lay out the stages. A share of traffic, a minimum duration or volume before anyone reads the numbers, and what is logged. A canary share with too little traffic behind it tells you nothing in a week; size the duration to the volume.

★ Block 3 · stagesStage Traffic to new Min duration / volume Logged shadow 0% served ________ inputs, both predictions, latency canary 1 ____% ________ ________ canary 2 ____% ________ ________ full 100% ________ ________ Old model kept deployed until: ________

Write the promotion gate for each stage. Numbers the new model must clear against the old model on the same period, and against the no-model baseline from session 2. If the new model cannot beat "do what the rule does today", it should not be promoted, however good it looked offline.

★ Block 4 · promotion criteriaGate Metric vs old model vs no-model baseline Else shadow -> c1 ____________ ____ ____ stay / back c1 -> c2 ____________ ____ ____ stay / back c2 -> full ____________ ____ ____ stay / back Constructed example, Elec2 price direction: agreement with the old model and accuracy on labelled rows, vs "repeat the previous half-hour", which scores 0.8533 on the full file (session 2). Your numbers will differ.

Write the rollback. Four lines, and the last one is the one leaders should ask to see. A rollback with no rehearsal date has not been tested.

★ Block 5 · the rollbackTrigger (the number, or the event): ______________________ Who pulls it, without asking anyone: ______________________ How long it takes, timed: ________ minutes Last rehearsed on: ________ (a date, or "never")

Name the skew check that runs during shadow. List the features computed in two places, the training pipeline and the serving path, and how each is compared. These are the features Rule 32 would have you merge into one computation.

★ Block 6 · the skew checkFeature Training source Serving source Tolerance ________________ ________________ ________________ ______ ________________ ________________ ________________ ______ Serving-time features logged for training (Rule 29): yes / no Next-day vs live performance compared (Rule 37): yes / no
What you would build

A shadow comparison you can run in a day. During the shadow stage the serving path logs, for every request, the features it used and both models' predictions. This script reads that log, measures how often the two models agree, then recomputes each feature with the training pipeline on the same rows and flags any feature whose serving-time mean drifts from the training-pipeline mean by more than a tolerance you set.

★ shadow_check.pyimport pandas as pd TOL = 0.01 # relative tolerance per feature; set your own log = pd.read_parquet("serving_log.parquet") # one row per request in the shadow period # columns: request_id, ts, pred_old, pred_new, and every feature as served, named f_* agree = (log["pred_old"] == log["pred_new"]).mean() print("agreement, old vs new:", round(agree, 4)) feats = [c for c in log.columns if c.startswith("f_")] # training_features(): your training pipeline's feature code, run on the same rows train = training_features(log[["request_id", "ts"]]) both = log.merge(train, on="request_id", suffixes=("_serve", "_train")) for f in feats: serve, trained = both[f + "_serve"], both[f + "_train"] diff = (serve - trained).mean() scale = trained.abs().mean() or 1.0 flag = "SKEW" if abs(diff) / scale > TOL else "ok" print(f, round(diff, 5), flag) # your numbers will differ

A mean difference is the first, cheapest check; a feature can match on average and still differ row by row, so look at the flagged ones by hand. The serving path, the router, the log itself and the deploy scripts are built in DataOps session b6 ↗.

Time the rollback with a stopwatch, not an estimate. Put the measured minutes and the rehearsal date on the plan's first line. Session 6 asks whether a model should still be running, and "we can switch it off in four minutes, we did it last month" is a much stronger answer than "we could roll back if we had to".

Homework

Before session 4

30 min
  1. Place one live model on the automation ladder, and write the step you would stop at, with the reason. If the model is at full automation and the honest answer is "partial", that is a finding.
  2. Draw the traffic path for your current deploy. Where a request enters, what decides which model answers it, and whose answer is served. If nobody can draw it, you are deploying all at once without having chosen to.
  3. Rehearse a rollback and time it. On a quiet day, in the real environment or the closest thing to it. Write down the minutes, the person who did it, and anything that surprised them.
  4. List the features computed in two places. For each, name the training source and the serving source. The list is the start of your skew check and of a Rule 32 conversation with the team that owns the serving path.
Check yourself

Three questions

Clear all three and session 3 gets stamped in your passport.

1 · A team ran the new model in shadow mode for a month and wants to skip the canary because "shadow already proved it works". What can shadow mode not tell them?

Shadow runs on real inputs at real load, so it can show skew, agreement and latency. Its answers are never served, so it cannot measure what happens when they are. That is what the canary is for.

2 · Why does the ML Test Score single out training/serving skew among its 28 tests?

Every test scores the same, and the final score is the minimum of the four sections. Skew is singled out because it matters most and was the least often in place, often because a feature is computed by two different pieces of code.

3 · A credit analyst approves every loan today. One wrong automated approval is expensive. Which rollout fits?

A person already makes the decision, so shadow mode is almost free and compares the model with the analyst on real cases. The high cost of an error then argues for a small canary before any wider share.

Sources covered

What this session teaches, and where it came from

✓Ng, Machine Learning in Production, week 1: deployment patterns and degrees of automationWeek title read on the DeepLearning.AI and Coursera pages; lecture content, including shadow, canary "maybe 5%", blue-green, the five degrees and the inspection example, reported from compiled lecture notes. Videos and certificate stay official
✓Breck et al. 2017, The ML Test Score: Infra 6-7 and Monitor 3Read at source: the canary test, the rollback test in its short form, training/serving skew, the 36 teams and the 80 percent finding
✓Zinkevich, Rules of Machine Learning: Rules 29, 32 and 37Read at source: log serving-time features, re-use code between training and serving, measure training/serving skew
◐Rollout shares and durationsEvery percentage beyond Ng's "maybe 5%", and every stage duration, is constructed for the plan and labelled so
◐Deploy tooling: routers, serving, deploy scriptsNot taught here; built in DataOps b6

Every fact on this page, and its verification tier, is recorded in the course's source map.

Session 3 cheat sheet · pin this

Five degrees of automationHuman only, shadow, AI assistance, partial, full. Write down the step you stop at.
Human in the loopAI assistance and partial automation. Partial is where most projects should aim first.
Shadow proves skew, not impactReal inputs, nobody acts on the output, so it cannot measure what acting would do.
Canary limits blast radius"Maybe 5%" first, and a promotion rule written before it starts.
Blue-green buys instant rollbackTwo full stacks, one switch. The old one must stay truly deployable.
Rollback: rehearsed, timed, ownedA trigger, a person, the minutes, and the date it last ran.