ML System Design · Module 21 of 47 · 12 concepts · about 14 min

Monitoring and Drift

Knowing whether a live model still works: the four layers to watch, the kinds of drift and how to measure them, monitoring when labels are late or missing, watching segments, and designing alerts that people act on rather than ignore.

At work: What turns 'the model got worse three months ago and nobody noticed' into an alert the same morning. Usually owned by the team that owns the model, with platform tooling underneath.

Four layers to monitor

What it is

Watch a live model at four layers, from the machine up to the business:

  • System: requests, errors, latency, resource use. Is the service healthy?
  • Data: input features: missing values, ranges, freshness, distributions. Are the inputs normal?
  • Model: predictions and, when labels arrive, accuracy. Is the model behaving as expected?
  • Business: the outcomes it exists for: orders, fraud losses, complaints. Is it still helping?

Why it matters

Each layer catches failures the others miss.

  • A perfectly healthy service can serve terrible predictions.
  • Inputs can drift while accuracy holds, or accuracy can fall while inputs look normal (concept drift).
  • Business metrics are the final judge, but slow and noisy, and moved by many things besides the model.

In the real world: Kirana Kart's ETA dashboard has one row per layer: latency and errors; feature freshness and nulls; average predicted minutes and live error; complaints about late delivery.

Visual example

Layers

The higher the layer, the slower but more meaningful the signal.

What to watch at each layer, for the ETA model
layersignalshow fastcatches
Systemp99 latency, error rate, fallback rateSecondsOutages, overload, bad deploys
DataNulls, ranges, freshness, distributionsMinutesBroken pipelines, upstream changes
ModelPrediction distribution; error once deliveredMinutes to an hourDrift, skew, bad models
BusinessLate-delivery complaints, cancellationsDaysWhether it still helps

Stopping at the system layer because that is what the infrastructure provides out of the box.

Kinds of drift

What it is

Drift is change over time that makes a model less accurate. Four kinds:

  • Data drift (covariate shift): the inputs change. Bigger baskets during a festival; a new city with longer distances.
  • Label drift (prior shift): how common each outcome is changes. Fraud rises from 0.5% to 1.5% during an attack.
  • Concept drift: the relationship between inputs and outcome changes. The same distance now takes longer because of new road works; fraudsters change tactics.
  • Prediction drift: the model's outputs change, a symptom of any of the above, or of a bug.

Why it matters

The kind of drift decides the response.

  • Data drift into ranges the model has seen may be harmless; into new ranges it is risky.
  • Label drift can often be handled by recalibrating or moving the threshold.
  • Concept drift needs retraining on recent data, and sometimes new features.
  • Sudden changes usually mean a bug or an event; gradual ones mean the world is moving.

In the real world: During a heavy-rain week, Kirana Kart's ETA inputs barely change but delivery times rise for the same distances, which is concept drift; a 'rain now' feature fixed it for good.

Retraining at the first sign of input drift. If the drift is a broken pipeline sending zeros, retraining teaches the model the bug.

Measuring drift

What it is

Common ways to compare a feature's live distribution with its training distribution:

  • Population stability index (PSI): bin the values, compare each bin's share. Under 0.1 is usually stable, 0.1–0.25 a moderate shift, over 0.25 large.
  • Kolmogorov–Smirnov test: the largest gap between two cumulative distributions, for numbers.
  • Chi-square test: for categories.
  • Jensen–Shannon or Wasserstein distance: smooth measures of how far apart two distributions are.

Why it matters

A number per feature makes drift visible and comparable.

  • PSI is popular because it is simple, works for any binned feature, and shows which bins moved.
  • Statistical tests become 'significant' for tiny, harmless shifts once samples are large, so a size measure like PSI is often more useful than a p-value.

In the real world: Credit-risk teams have used PSI for decades to monitor scorecards; ML monitoring tools such as Evidently and WhyLabs offer it alongside the other measures.

Visual example

Computed

Share of orders by basket value, training month vs festival week. PSI = 0.203: a moderate shift, mostly from fewer small baskets and many more large ones.

PSI = Σ (live − train) × ln(live ÷ train)
basket valuetrainingfestival weekcontribution
under ₹20020%10%0.069
₹200–50030%25%0.009
₹500–1,00030%30%0
₹1,000–2,00015%20%0.014
over ₹2,0005%15%0.11

Alerting on test p-values with millions of rows. Every feature becomes 'significantly different' every day, and the alerts are ignored.

Monitoring without labels

What it is

Labels often arrive late or never. Watch what you can see now:

  • prediction drift: the distribution of scores or outputs;
  • input drift, weighted by how important each feature is to the model;
  • proxy outcomes that arrive fast: complaints, manual overrides, review decisions, early returns;
  • confidence: a rise in uncertain predictions suggests unfamiliar inputs.

Why it matters

Waiting for labels can mean months of unnoticed decline.

  • These signals do not prove accuracy has fallen, but they say where to look.
  • Weighting drift by feature importance avoids alarms about features the model barely uses.

In the real world: Kirana Kart's fraud model is watched daily through its flag rate, the share of flags reviewers overturn, and customer disputes, long before chargebacks arrive.

Treating 'no drift detected' as 'model is fine'. Concept drift can leave inputs and predictions unchanged while their link to reality breaks; only labels, or good proxies, catch it.

Monitoring with delayed labels

What it is

When labels arrive over weeks, measure performance by cohort:

  • group predictions by the week they were made;
  • for each cohort, compute accuracy on the labels arrived so far;
  • compare each cohort with older cohorts at the same age, not with fully labelled ones.

Why it matters

Recent cohorts always look different, because their labels are incomplete.

  • Comparing a 7-day-old cohort with a 90-day-old one shows a fake decline.
  • Comparing it with how earlier cohorts looked at 7 days shows a real one.

In the real world: Payment and lending teams track each month's cohort at fixed ages (7, 30, 60, 90 days) and compare like with like.

Visual example

Computed

Fraud recall by weekly cohort. Young cohorts look worse simply because their chargebacks have not arrived.

Label arrival shares from module 6; recall on labels so far
cohort age (days)labels arrivedrecall so farcompare with
90100%84%Earlier cohorts at 90 days
6095%83%Earlier cohorts at 60 days
3075%81%Earlier cohorts at 30 days
1450%71%Earlier cohorts at 14 days
730%62%Earlier cohorts at 7 days

Plotting one 'accuracy over time' line. It always dips at the end because the newest predictions have the fewest labels, and the team panics every week.

Practise it: Design Model Monitoring

Data quality in production

What it is

The checks that guard training data (module 8) should also run on live features:

  • share of missing values per feature;
  • share of default values (0, -1, 'unknown'): a jump means an upstream source broke;
  • ranges and allowed categories;
  • freshness: age of each online feature;
  • volume: requests per segment, compared with the usual pattern.

Why it matters

Live data breaks more often than models decay.

  • A sudden jump in defaults for one feature is the most common sign of a broken upstream service.
  • These checks are cheap, fast and precise about the cause.

In the real world: An alert on 'store queue length = 0 for 40% of requests' points Kirana Kart's on-call engineer straight to a stalled streaming job.

Monitoring only the model's output. By the time predictions look odd, the broken input has been feeding them for hours; watch inputs directly.

Practise it: Design Feature Monitoring

Watching segments

What it is

Monitor key metrics per segment, not only overall:

  • by city, store, device, app version, customer type;
  • especially segments that matter commercially or are vulnerable (new users, small cities);
  • with enough volume per segment for the numbers to mean something.

Why it matters

Many failures are local.

  • A new app version on one platform sends a feature in the wrong units: overall accuracy dips slightly; that platform's accuracy collapses.
  • Averages dilute such failures until they are invisible.

In the real world: Kirana Kart monitors ETA error by city and by app version; a jump in one app version's error has twice revealed a client bug in how the address was sent.

Monitoring hundreds of tiny segments with fixed thresholds. Small samples fluctuate wildly and the alerts become noise; set limits that account for sample size.

Designing alerts people act on

What it is

An alert is useful only if someone acts on it. Good alerting:

  • alerts on symptoms that matter (errors, stale features, prediction drift, business impact), not every metric;
  • requires a condition to hold for a while (several consecutive checks) before firing, to ignore blips;
  • groups related alerts (one upstream failure, one alert, not fifty);
  • ranks by impact: traffic affected, money at risk;
  • links to a runbook: what to check and what to do.

Why it matters

Too many alerts are as bad as none.

  • People learn to ignore a noisy channel, and then miss the real incident.
  • Every alert should be either actionable or removed.

In the real world: Kirana Kart reviews its ML alerts monthly: any alert that fired without leading to action is retuned or deleted.

# Fire only if the condition holds for 3 consecutive 5-minute checks, and say how much traffic it affects.
rule = Alert(
    name="eta_feature_store_queue_stale",
    condition=lambda w: w.share_stale("orders_waiting_now") > 0.05,
    for_consecutive=3,
    severity=lambda w: "page" if w.requests_affected_per_min > 100 else "ticket",
    runbook="https://runbooks.internal/eta/stale-queue-feature",
    group_by=["upstream_job"],
)

An alert on every feature's PSI at 0.1. With 200 features, several fire every day by chance, and within a month nobody reads them.

Monitoring at scale with sketches

What it is

Storing every prediction and feature to compute distributions is expensive at millions of requests an hour. Sketches summarise a stream in a small, fixed amount of memory:

  • quantile sketches (t-digest, KLL) estimate percentiles;
  • HyperLogLog estimates the number of distinct values;
  • frequency sketches (count-min) estimate how often values appear.

Sketches from many servers and time windows can be merged.

Why it matters

They make per-feature, per-segment monitoring affordable.

  • A few kilobytes per feature per window instead of every value.
  • Accuracy is good enough for drift detection.

In the real world: WhyLabs' open-source whylogs library profiles data with sketches so that drift can be monitored without storing raw data.

Sampling 0.1% of requests to save cost and then monitoring small segments. A city with 1% of traffic leaves a handful of sampled rows; sketches over all traffic do far better.

Owning a model in production

What it is

Every live model needs clear ownership:

  • a named owning team and on-call rotation;
  • dashboards for the four layers;
  • runbooks for common incidents: stale feature, drift, bad release;
  • a review cadence: monthly look at performance, slices, alerts and costs.

Why it matters

Models without owners decay quietly.

  • The person who built it moves on; nobody notices its slow decline.
  • Clear ownership is the cheapest monitoring there is.

In the real world: Kirana Kart's model registry will not let a model reach production without an owning team and a runbook link.

Visual example

Response

Mitigate first, then find the cause (module 23).

From alert to resolution

  1. AlertImpact and a runbook link
  2. TriageWhich layer? Since when?
  3. MitigateminutesRoll back or fall back
  4. DiagnoseData, model or code
  5. Fix and reviewAdd a check so it cannot recur

Handing a model to a central 'operations' team that does not understand it. They can restart services, but not tell a real drift from a harmless one.

Interview questions: monitoring and drift

What it is

The questions interviewers ask about monitoring and drift, from the first screening call to the senior round. Cover the answer, say yours aloud, then compare.

Why it matters

Reading an idea and explaining it are different skills.

  • Each answer below is the two or three sentences an interviewer is listening for.
  • The reasoning behind each one is in the cards above. If an answer surprises you, go back to that card.

In the real world: Model monitoring is a standard section of ML design interviews and the whole subject of MLOps rounds. 'What would you monitor?' is asked in nearly every one.

Q: What would you monitor for a production model?

Four layers: system health (latency, errors, fallbacks), input data (nulls, defaults, ranges, freshness, drift), model behaviour (prediction distribution, accuracy as labels arrive) and business outcomes, per segment as well as overall.

Q: What is the difference between data drift and concept drift?

Data drift is a change in the inputs' distribution; concept drift is a change in how inputs relate to the outcome. Concept drift can occur with no input change and needs retraining or new features.

Q: How do you detect drift?

Compare live and training distributions per feature with PSI, KS or chi-square tests, or distances such as Jensen–Shannon, weighted by feature importance and judged by effect size rather than p-values alone.

Q: How do you monitor when labels are delayed?

Prediction and input drift, fast proxy outcomes, and cohort-based accuracy compared at equal ages, not against fully labelled older data.

Q: How do you avoid alert fatigue?

Alert on symptoms that matter, require persistence, group related alerts, rank by impact, attach runbooks, and delete alerts nobody acts on.

Q: Your model's input distribution shifted. Do you retrain?

First check whether it is a data bug; then whether accuracy or proxies actually fell. Retrain on recent data if it is a real, lasting change that hurts performance.

Listing only latency and error rate.

Practise it: Diagnose Model Drift, Design Feature Monitoring, Design Model Monitoring, Design a Real-Time Fraud Detection System

Exercise: build a drift monitor

What it is

A short build that uses this module's ideas. Write it yourself before looking anything up; the checks at the end tell you whether it works.

Why it matters

An idea you have only read fades in a week.

  • Building it once, even in fifty lines, is what makes it yours.
  • Interviewers can tell the difference between someone who has read about a loop and someone who has debugged one.

In the real world: Monitoring notebooks like this often become the first version of a team's real drift dashboard.

Your task. Monitor a model's inputs and predictions over simulated weeks, and raise alerts only for changes that matter.

Steps

  1. Take a model and its training data from an earlier exercise.
  2. Simulate eight weeks of live data: weeks 1–3 normal, week 4 a broken feature (many zeros), weeks 5–8 a gradual shift in one important feature.
  3. Compute PSI per feature per week against training, and the share of nulls and defaults.
  4. Compute the prediction distribution each week and its PSI.
  5. Write alert rules: data-quality alerts for nulls and defaults; drift alerts weighted by feature importance with a three-week persistence rule.
  6. Run them over the eight weeks and list what fired and when.

You are done when

  • The broken feature fires a data-quality alert in week 4, not a drift alert.
  • The gradual shift fires once, after the persistence window, not every week.
  • No alert fires in weeks 1–3.

Stretch. Try Evidently or whylogs on the same data and compare their reports with yours.