Unit 7 · ML & applied AI · Lesson 13 of 13
Model serving, monitoring and drift
Step 1: Learn the ideas
- Batch, online and streaming inference; hosted versus self-hosted models
- Latency and cost levers: batching, caching, model size, quantization, distillation
- Training-serving skew and feature consistency
- Covariate drift, label shift and concept drift
- Monitoring with delayed or missing labels
- Timeouts, retries, fallbacks, rate limits and circuit breakers
- Versioning, shadow, canary and A/B rollouts
- Feedback loops and ML technical debt
Why it matters
A model that scores well offline only creates value if it serves predictions within latency and cost budgets, keeps working as data changes, and fails safely. Production-focused questions in ML and applied AI interviews target exactly this: how you would deploy, what you would monitor, and what happens when a model provider is slow or the input distribution shifts. Cloud and SRE knowledge transfers directly, with ML-specific additions.
Core ideas
Serving patterns. Batch inference precomputes predictions on a schedule: cheap and simple, but stale. Online inference answers each request within a latency budget. Streaming updates features or predictions from event streams. For LLM features the main choice is a hosted API (fast to start, but provider limits and data-handling terms apply) versus self-hosted open models (more control and possibly lower unit cost at scale, but you own GPUs, scaling and upgrades).
Latency and cost levers.
- Batching raises accelerator utilization and throughput at the cost of queueing delay; LLM servers use continuous batching, adding and removing sequences at every decoding step.
- Caching: exact-match result caches for repeated requests, provider prompt caching for long shared prefixes, and caches for embeddings and retrieval results. Semantic caches that match similar queries can return wrong answers, and every cache must be scoped by tenant.
- Model size: route easy requests to smaller models and escalate hard ones; quantization and distillation cut memory and cost with quality losses you must measure.
- Output length: each generated token is a sequential decoding step, so long outputs usually dominate LLM latency (very long prompts shift cost to prefill); constrain verbosity and stream tokens to improve perceived latency.
Training-serving skew. If features are computed differently online and offline, or joined against tables that have since changed, the served model is not the one you evaluated. Share feature code between training and serving, log the features actually served and train on those logs where possible, and compare online and offline feature distributions.
Drift. Covariate drift: the input distribution changes (a new customer segment, new phrasing). Label shift: class priors change (the fraud rate doubles), which breaks calibration and thresholds. Concept drift: the relationship between inputs and outputs changes (what counts as spam evolves). Detect drift by comparing feature and prediction distributions with a reference window (population stability index, two-sample tests, or embedding-distance statistics for text), and confirm impact with outcome metrics once labels arrive. Labels are often delayed or never arrive, so monitor proxies such as user corrections, escalation rates and acceptance of suggestions, and sample outputs for human review. Treat a drift alert as a hypothesis: rule out a pipeline bug that changed the inputs before retraining.
Monitoring layers. Service health (latency percentiles, errors, saturation); data quality (schema, missing values, ranges); model behavior (prediction distribution, confidence, refusal rate for LLMs); outcomes (quality and business metrics); and cost per request. Alert on the few signals that indicate user harm.
Reliability for model calls. Treat a model like any remote dependency that can be slow, rate-limited, unavailable or wrong. Derive timeouts from the latency budget; retry only idempotent calls, with exponential backoff, jitter and a retry budget; fall back to a smaller model, a cached answer, a rule-based default or a clear "unavailable" message; queue requests client-side to respect provider rate limits; and use circuit breakers to stop hammering a failing dependency. Validate model outputs before they reach downstream systems.
Releases. Version models, prompts, data and feature code together. Gate releases on offline evaluations, then run in shadow (scoring live traffic without serving it), canary to a small share of traffic, and A/B test where the metric allows; keep rollback one step away. Watch for feedback loops, where a model's own outputs shape its future training data.
Common misconceptions
- "Healthy latency and error rates mean the model is fine." Models fail silently; monitor inputs, predictions and outcomes.
- "Detected drift means retrain now." First rule out pipeline bugs and confirm a performance impact; retraining on broken data makes things worse.
- "Bigger batches are always better." They raise throughput but add queueing latency; size them to the latency budget.
- "Retries make LLM calls reliable." Unbounded retries amplify outages and can duplicate side effects; use budgets and idempotency.
- "Good offline evaluation guarantees online performance." Skew, drift and user behavior differ; use shadow and canary releases.
- "A semantic cache is a free speedup." Similar is not identical; it can return wrong or cross-tenant answers.
How to approach it
Reuse your cloud and SRE vocabulary and add the ML layers: skew, drift, delayed labels and evaluation gates. Deploy a small model behind an API with logging and a drift report, and write a failure-mode table for an LLM feature. In interviews, structure answers as serving pattern, budgets, monitoring layers, failure handling and release process.
Suggested order
- 1Read "Hidden Technical Debt in Machine Learning Systems" and list which debts apply to a system you know.
- 2Read the Rules of ML "Monitoring" rules (#8 to #11) and "Training-Serving Skew" rules (#29 to #37).
- 3Read D2L 4.7 (Environment and Distribution Shift) for covariate shift, label shift and concept shift and their corrections.
- 4Read Chip Huyen’s "Data Distribution Shifts and Monitoring" for detection methods and what to monitor when labels are delayed.
- 5Read the ML Test Score paper and turn its data, model, infrastructure and monitoring tests into a checklist for one model.
- 6Do the deployment and failure-mode exercise in the practice guidance.
Step 2: Check off what you can do
Tap each one you can genuinely do or explain. Each earns 10 XP.
Step 3: Go deeper
Hidden Technical Debt in Machine Learning SystemsStart here
NeurIPS ProceedingsSystem-level ML risks: entanglement, data dependencies, feedback loops, glue code and configuration debt.
Open(opens in a new tab)Link responded, 5 Oct 2026Rules of Machine Learning: Best Practices for ML EngineeringStart here
Google for DevelopersSection: Monitoring (Rules #8 to #11) and Training-Serving Skew (Rules #29 to #37)
Practical rules on freshness, silent failures, feature ownership and training-serving skew.
Open(opens in a new tab)Link responded, 5 Oct 2026Dive into Deep Learning
d2l.ai (open-source book)Section: 4.7. Environment and Distribution Shift
Definitions of covariate, label and concept shift, with standard corrections and their assumptions.
Open(opens in a new tab)Link responded, 5 Oct 2026Data Distribution Shifts and Monitoring
Chip Huyen's blog (practitioner)Operational detection of distribution shift and monitoring when labels are delayed or missing.
Open(opens in a new tab)Link responded, 5 Oct 2026The ML Test Score: A Rubric for ML Production Readiness and Technical Debt Reduction
Google ResearchConcrete production-readiness tests for data, models, infrastructure and monitoring.
Open(opens in a new tab)Link responded, 5 Oct 2026
Step 4: Practice
Deploy a small scikit-learn or open-weights model behind an HTTP endpoint (FastAPI or similar) that logs inputs, outputs, model version and latency. Replay a dataset with a deliberate shift (change one feature’s distribution, or swap in text from another domain) and build a simple drift report against the training window. For an LLM feature, write a failure-mode table covering provider timeout, rate limiting, malformed output, a cost spike and a quality regression after a model update, with the detection signal and the fallback for each. Add a timeout, a retry budget and a fallback path to your endpoint and test them against an artificially slow dependency.
No external problems are linked; follow the guidance above.
Record attempts on each problem’s page (+15 XP, +10 more when solved on your own).
Step 5: Test yourself
Answer each one out loud or on paper before you finish the lesson.
- Question 1Which monitoring signals catch a model failure while service health stays green?
- Question 2Labels arrive 60 days after prediction. What do you monitor in the meantime?
- Question 3How does batching trade throughput against latency?
- Question 4When is caching LLM responses unsafe?
- Question 5What would you check before retraining in response to a drift alert?
- Question 6How should an application behave when its LLM provider starts rate-limiting it?
You’re done when you can
- Design serving, monitoring and fallbacks for a described model under explicit latency and cost budgets in under ten minutes.
- Explain covariate drift, label shift and concept drift with an example of each and how you would detect them.
- Explain training-serving skew and two concrete prevention measures.
- Describe a safe rollout from offline gate to shadow, canary and rollback.


