Simple Algorithm
Machine Learning · Convergence · 24 min

ML Systems: Technical Debt & Monitoring

Feedback loops, testing and monitoring models in the wild.

In a production system the model is a small box, surrounded by data pipelines, configuration, serving code and monitoring, and most failures happen outside the box. This lesson treats the whole system as an object of study: the forms of hidden technical debt, a rubric for testing ML systems, data validation at scale, change detection with a provable false-alarm rate, and the theory of feedback loops, in which a model's predictions reshape the data it will later learn from.

What you’ll learn

  • Identify the ML-specific forms of technical debt, such as entanglement, correction cascades, undeclared consumers, data dependencies and feedback loops, and their mitigations.
  • Apply the ML Test Score rubric and schema-based data validation, and explain why significance tests make poor alarms at production scale.
  • Derive the CUSUM change detector, prove that its average run length to a false alarm is at least ehe^h, and estimate its detection delay from a KL divergence.
  • Formalize performative prediction, prove that repeated retraining converges to a performatively stable point when ε<γ/β\varepsilon<\gamma/\beta, and bound the distance between stable and optimal points.

The model is the small box

Sculley et al. (2015) drew a real-world ML system as a large diagram in which the ML code is a small black box in the middle, and the infrastructure around it, from data collection and feature extraction to configuration, resource management and monitoring, is vast and complex. Their argument, in the language of software engineering, is that ML makes it easy to incur technical debt: quick wins whose maintenance cost compounds silently. Many of the debts have no analogue in ordinary software, because the system's behavior is specified by data rather than by code.

DebtWhat goes wrongMitigation
Entanglement"Changing Anything Changes Everything" (CACE): shifting one feature's distribution, adding or removing a feature, or changing a hyperparameter re-weights all the othersisolate sub-models where the problem decomposes; monitor prediction behavior slice by slice
Correction cascadesa model ma′m'_a learns a small correction on top of mam_a for a related problem; improving mam_a now breaks ma′m'_aadd features to mam_a that distinguish the cases, or build the new model directly
Undeclared consumersother systems silently read a model's outputs, so changing the model changes them, possibly closing a hidden loopaccess controls and service agreements on model outputs
Unstable and underutilized data dependenciesinput signals produced by other teams change without notice; legacy, bundled, barely useful ("epsilon") and redundant correlated features add risk for little gainversioned copies of input signals; regular leave-one-feature-out audits
Feedback loopsdirect: a model influences the selection of its own future training data; hidden: two systems influence each other through the worldrandomization, holding out data from the model's influence, bandit methods
Glue code and pipeline junglesmost code converts data in and out of general-purpose packages; preparation pipelines grow by accretiondesign data collection and features holistically; wrap packages in common APIs
Configuration debt; fixed thresholdsmore lines of configuration than code, rarely tested; decision thresholds tuned once on data that no longer existreview and test configuration like code; learn thresholds on held-out data and re-learn them
All categories are from Sculley et al. (2015). Paleyes, Urma & Lawrence (2022) surveyed published case studies of deployments and found practitioners reporting problems at every stage of the workflow, from data management and model learning to verification and deployment.
Check your understanding

A team removes a feature whose learned weight was close to zero, retrains, and finds that the model's behavior changed a lot for one customer segment. What is the most likely explanation?

  1. A bug: a near-zero weight means the feature had no influence, so nothing should change
  2. Entanglement: a correlated feature had absorbed part of the effect, and removing one re-weighted the others, especially where they disagree
  3. Label shift between the old and new training sets
  4. The retrained model overfit because it has fewer features
Show the answer

B. Entanglement: a correlated feature had absorbed part of the effect, and removing one re-weighted the others, especially where they disagree

Weights of correlated features are jointly determined; a small weight does not mean small influence on the fit as a whole. Removing a feature changes the optimal weights of all the others, and the change shows up most where the correlated features carry different information, for example in a particular segment. That is CACE.

Testing and validating ML systems

The ML Test Score (Breck, Cai, Nielsen, Salib & Sculley, 2017) turns production readiness into a rubric of 28 tests in four sections of seven: data (feature expectations are captured in a schema; every feature is beneficial and worth its cost; feature code is tested), model (offline proxy metrics correlate with live ones; the impact of staleness is known; a simpler model is not better), infrastructure (training is reproducible; the full pipeline is integration-tested; models are canaried and can be rolled back quickly) and monitoring (data invariants hold in training and serving; training and serving compute the same features; models are not too stale; no regressions in prediction quality). A test earns half a point if run manually with documented results and a full point if automated and run repeatedly; each section's points are summed, and the final score is the minimum over the four sections, so neglecting any one area caps the whole.

Data validation (Breck, Polyzotis, Roy, Whang & Zinkevich, 2019) treats data errors like software errors. Each batch of training data is checked against a schema that encodes expected types, domains, presence and value constraints, and the schema evolves through suggested edits that a person approves. Serving data are compared continuously with training data for three kinds of training–serving skew:

  • Feature skew: a feature takes different values for the same example in training and in serving, typically because two code paths compute it.
  • Distribution skew: the distribution of a feature differs, for example because of a flawed sampling scheme.
  • Scoring/serving skew: only some scored examples are served (ten videos shown out of a hundred scored), so unshown items never acquire labels, an implicit feedback loop.

For the distribution comparisons they deliberately avoided significance tests. In their experiment, replacing 10,000 of 100 million standard normal draws with draws from a wider normal, a 0.01% contamination no one would care about, made a χ² test reject at the 1% level in 7 of 10 trials. They used instead an interpretable distance with a threshold teams can set directly, the L∞L_\infty distance max⁡i∣pi−qi∣\max_i\abs{p_i-q_i} between categorical distributions.

Testing extends to research practice. The NeurIPS 2019 reproducibility program (Pineau et al., 2021) combined a code submission policy, a community-wide reproducibility challenge and a reproducibility checklist that authors answered at submission and again at the camera-ready stage, with questions such as whether the paper describes how experiments were run and defines the measures used to report results. It is the research counterpart of the ML Test Score: a list of mechanical checks that catches omissions before they become irreproducible claims.

Change detection with a guaranteed false-alarm rate

Monitoring is sequential: data arrive one observation (or batch) at a time, and a change can happen at an unknown time ν\nu. Testing afresh each day ignores the sequence; the classical answer is Page's (1954) cumulative-sum procedure. Suppose observations are i.i.d. with density f0f_0 before the change and f1f_1 after. The monitored quantity can be anything with a stable reference distribution: a feature's mean, the fraction of positive predictions, or once labels arrive the error indicator.

DerivationCUSUM, its false alarms and its delay
  1. Λt=log⁡f1(xt)f0(xt),E0[Λt]=−DKL(f0 ∥ f1)<0<DKL(f1 ∥ f0)=E1[Λt]\Lambda_t=\log\frac{f_1(x_t)}{f_0(x_t)},\qquad\E_0[\Lambda_t]=-\KL(f_0\,\|\,f_1)<0<\KL(f_1\,\|\,f_0)=\E_1[\Lambda_t]

    Each observation contributes a log-likelihood ratio, negative on average before the change and positive after it:

  2. Wt=max⁡(0, Wt−1+Λt)=max⁡1≤k≤t+1 ∑i=ktΛi,τh=min⁡{t: Wt≥h}W_t=\max\big(0,\ W_{t-1}+\Lambda_t\big)=\max_{1\le k\le t+1}\ \sum_{i=k}^t\Lambda_i,\qquad\tau_h=\min\{t:\ W_t\ge h\}

    CUSUM keeps the log-likelihood ratio of the most likely change point so far, clipped at zero, and alarms when it reaches a threshold hh:

  3. Pr⁡0[sup⁡n∑i=1nΛi≥h]≤e−h⟹E0[τh] ≥ eh\Pr_0\Big[\sup_{n}\sum_{i=1}^n\Lambda_i\ge h\Big]\le e^{-h}\quad\Longrightarrow\quad\E_0[\tau_h]\ \ge\ e^{h}

    False alarms. Between returns to zero, WW runs a one-sided sequential test from 0. Under f0f_0, exp⁡(∑i≤nΛi)\exp\big(\sum_{i\le n}\Lambda_i\big) is a nonnegative martingale with mean 1, so by Ville's maximal inequality an excursion reaches hh with probability at most e−he^{-h}. Excursions are independent and each lasts at least one step, so the number of them before the first alarm is geometric with mean at least ehe^h:

  4. E1[τh]≈hDKL(f1 ∥ f0),optimal:  log⁡γDKL(f1 ∥ f0)(1+o(1))\E_1[\tau_h]\approx\frac{h}{\KL(f_1\,\|\,f_0)},\qquad\text{optimal: }\ \frac{\log\gamma}{\KL(f_1\,\|\,f_0)}\big(1+o(1)\big)

    Delay. After the change, WW climbs at an average rate of DKL(f1 ∥ f0)\KL(f_1\,\|\,f_0) per observation. From the worst start W=0W=0, Wald's identity says the unclipped sum needs (h+mean overshoot)/DKL(f1 ∥ f0)(h+\text{mean overshoot})/\KL(f_1\,\|\,f_0) observations to reach hh, and the resets at zero can only shorten that, so to first order the delay is h/DKL(f1 ∥ f0)h/\KL(f_1\,\|\,f_0). Lorden (1971) proved that no procedure whose mean time to false alarm is at least γ\gamma can have a worst-case delay asymptotically smaller than (log⁡γ)/DKL(f1 ∥ f0)(\log\gamma)/\KL(f_1\,\|\,f_0), so CUSUM with h=log⁡γh=\log\gamma is asymptotically optimal; Moustakides (1986) proved it exactly optimal for Lorden's criterion.

Predict before you look

A standardized monitoring statistic is N(0,1)\mathcal N(0,1) while all is well and N(0.5,1)\mathcal N(0.5,1) after a fault. You set h=ln⁡10,000≈9.2h=\ln10{,}000\approx9.2, so false alarms come at most once per 10,000 observations on average. About how many observations after the fault until CUSUM alarms?

Show the answer

74 observations

DKL(N(δ,1) ∥ N(0,1))=δ2/2=0.125\KL\big(\mathcal N(\delta,1)\,\|\,\mathcal N(0,1)\big)=\delta^2/2=0.125, so the delay is about 9.21/0.125≈749.21/0.125\approx74 observations (a simulation gives about 70: the resets at zero save a little more than the overshoot past hh costs). Here Λt=0.5 xt−0.125\Lambda_t=0.5\,x_t-0.125: CUSUM is a running sum of the observations minus half the shift, reset at zero. Halving the shift quadruples the delay; tightening the false-alarm rate tenfold adds only ln⁡10/0.125≈18\ln10/0.125\approx18 observations.

In practice f1f_1 is unknown, so one designs for the smallest shift worth detecting, or maximizes over a family of alternatives (generalized likelihood ratio). Monitoring hundreds of statistics multiplies false alarms by their number unless thresholds are raised accordingly, about ln⁡m\ln m more for mm independent streams at the same overall rate. Labels often arrive late; until they do, prediction-based statistics, including the label-shift estimate from the flagged rate, are the earliest signals available.

Feedback loops: when the model writes its own data

A direct feedback loop arises when a model influences the selection of its own future training data. Sculley et al. note that the principled treatment is a bandit algorithm, which accounts for the fact that you observe outcomes only for the actions you take, and that partial randomization is a practical mitigation. The simplest case shows what goes wrong without it.

The loop can also run through people. Jiang, Chiappa, Lattimore, György & Kohli (2019) modeled a user whose interest in an item grows when it is shown and clicked and shrinks when shown and ignored, and gave conditions under which repeated recommendation drives interest to degenerate, diverging to ±∞\pm\infty: echo chambers as a property of the dynamics. In their analysis and simulations, random exploration and a growing pool of candidate items slow the degeneration. Among the policies they compared, oracles that know the user's interests and exploit them fully degenerated fastest, Thompson sampling and UCB more slowly, and a purely random recommender slowest: the better a system exploits, the faster it narrows what the user is exposed to.

When the loop runs through strategic people who change their features to obtain a better decision, the setting is strategic classification (Hardt, Megiddo, Papadimitriou & Wootters, 2016). The framework below contains strategic classification as a special case; the interest dynamics above go beyond it, because there the data depend on the whole history of recommendations, not only on the model currently deployed.

Performative prediction

DerivationProof of the contraction
  1. Δ⊤∇f(G(θ′)) ≤ −γ∥Δ∥2\boldsymbol\Delta^\top\nabla f\big(G(\boldsymbol\theta')\big)\ \le\ -\gamma\norm{\boldsymbol\Delta}^2

    Write f(φ)=ED(θ)ℓ(Z;φ)f(\boldsymbol\varphi)=\E_{\mathcal D(\boldsymbol\theta)}\ell(Z;\boldsymbol\varphi), minimized by G(θ)G(\boldsymbol\theta), and f′f' for D(θ′)\mathcal D(\boldsymbol\theta'), minimized by G(θ′)G(\boldsymbol\theta'); let Δ=G(θ)−G(θ′)\boldsymbol\Delta=G(\boldsymbol\theta)-G(\boldsymbol\theta'). Strong convexity of ff and optimality of G(θ)G(\boldsymbol\theta) give:

  2. Δ⊤∇f(G(θ′)) ≥ Δ⊤∇f′(G(θ′))−εβ∥Δ∥∥θ−θ′∥ ≥ −εβ∥Δ∥∥θ−θ′∥\boldsymbol\Delta^\top\nabla f\big(G(\boldsymbol\theta')\big)\ \ge\ \boldsymbol\Delta^\top\nabla f'\big(G(\boldsymbol\theta')\big)-\varepsilon\beta\norm{\boldsymbol\Delta}\norm{\boldsymbol\theta-\boldsymbol\theta'}\ \ge\ -\varepsilon\beta\norm{\boldsymbol\Delta}\norm{\boldsymbol\theta-\boldsymbol\theta'}

    The function z↦Δ⊤∇θℓ(z;G(θ′))z\mapsto\boldsymbol\Delta^\top\nabla_{\boldsymbol\theta}\ell\big(z;G(\boldsymbol\theta')\big) is β∥Δ∥\beta\norm{\boldsymbol\Delta}-Lipschitz by joint smoothness. By Kantorovich–Rubinstein duality its expectations under the two distributions differ by at most β∥Δ∥ W1≤β∥Δ∥ ε∥θ−θ′∥\beta\norm{\boldsymbol\Delta}\,W_1\le\beta\norm{\boldsymbol\Delta}\,\varepsilon\norm{\boldsymbol\theta-\boldsymbol\theta'}, and under D(θ′)\mathcal D(\boldsymbol\theta') it is nonnegative by first-order optimality of G(θ′)G(\boldsymbol\theta') for f′f':

  3. ∥G(θ)−G(θ′)∥≤εβγ∥θ−θ′∥⟹∥θt−θPS∥≤(εβγ)t∥θ0−θPS∥\norm{G(\boldsymbol\theta)-G(\boldsymbol\theta')}\le\frac{\varepsilon\beta}{\gamma}\norm{\boldsymbol\theta-\boldsymbol\theta'}\quad\Longrightarrow\quad\norm{\boldsymbol\theta_t-\boldsymbol\theta_{\mathrm{PS}}}\le\Big(\frac{\varepsilon\beta}{\gamma}\Big)^t\norm{\boldsymbol\theta_0-\boldsymbol\theta_{\mathrm{PS}}}

    Combine the two inequalities and divide by γ∥Δ∥\gamma\norm{\boldsymbol\Delta}. For εβ/γ<1\varepsilon\beta/\gamma<1 the map GG is a contraction, and the Banach fixed-point theorem gives a unique fixed point, which is exactly a stable point, and geometric convergence:

Predict before you look

A model's loss is 11-strongly convex and 44-jointly smooth. Up to what sensitivity ε\varepsilon of the world's response does the theorem guarantee that retraining converges?

Show the answer

0.25

The condition is ε<γ/β=1/4\varepsilon<\gamma/\beta=1/4. At ε=0.1\varepsilon=0.1 the contraction factor is εβ/γ=0.4\varepsilon\beta/\gamma=0.4, so each retraining cuts the distance to the stable point by 60% and ten retrainings by a factor of about 10410^4. A ridge penalty λ2∥θ∥2\frac\lambda2\norm{\boldsymbol\theta}^2 raises both constants by λ\lambda, so γ/β\gamma/\beta grows toward 1 and the safe range widens: in this theory, regularization makes retraining more stable.

Stability is not optimality. A stable point is a fixed point of retraining: it is optimal given the distribution it has caused, ignoring that a different model would cause a different distribution. The performative risk can even be concave under all the assumptions above (Perdomo et al., 2020), so minimizing it directly is hard in general, and the bound 2Lzε/γ2L_z\varepsilon/\gamma is what makes retraining a reasonable proxy when the world reacts weakly.

Key takeaways

  • Most of an ML system is not the model. Entanglement (CACE), correction cascades, undeclared consumers, unstable data dependencies, feedback loops and configuration are ML-specific technical debt.
  • The ML Test Score grades data, model, infrastructure and monitoring tests and takes the minimum; schema-based data validation catches feature, distribution and scoring/serving skew, with effect-size thresholds rather than p-values at scale.
  • CUSUM, Wt=max⁡(0,Wt−1+Λt)W_t=\max(0,W_{t-1}+\Lambda_t), has mean time to false alarm at least ehe^h and delay about h/DKL(f1 ∥ f0)h/\KL(f_1\,\|\,f_0), which is asymptotically optimal (Lorden) and exactly optimal in Lorden's sense (Moustakides).
  • A model that chooses which outcomes it sees can lock into its mistakes, like a greedy bandit; exploration and randomization keep the data informative.
  • Performative prediction: with γ\gamma-strongly convex, β\beta-jointly smooth losses and an ε\varepsilon-sensitive world, retraining contracts at rate εβ/γ\varepsilon\beta/\gamma to a stable point within 2Lzε/γ2L_z\varepsilon/\gamma of the optimum; for ε>γ/β\varepsilon>\gamma/\beta it can fail.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

A team scores its system with the ML Test Score: data 5, model 4.5, infrastructure 3, monitoring 1. What is its final score?

  1. 13.5
  2. 3.375
  3. 5
  4. 1
Show the answer

D. 1

The final score is the minimum over the four sections, so the neglected monitoring caps the whole at 1. The rule is deliberate: a system is only as production-ready as its weakest area.

Question 2

You want CUSUM to raise a false alarm no more than once per 1,000 observations on average. What is the smallest threshold on the log-likelihood-ratio scale that the bound E0[τh]≥eh\E_0[\tau_h]\ge e^h certifies?

  1. h=0.001h=0.001
  2. h=3h=3
  3. h=ln⁡1000≈6.9h=\ln1000\approx6.9
  4. h=1000h=1000
Show the answer

C. h=ln⁡1000≈6.9h=\ln1000\approx6.9

E0[τh]≥eh\E_0[\tau_h]\ge e^h, so h=ln⁡1000h=\ln1000 suffices. The threshold enters through its exponential, which is why tightening the false-alarm rate is cheap in delay: each tenfold reduction adds only ln⁡10/DKL(f1 ∥ f0)\ln10/\KL(f_1\,\|\,f_0) observations of delay.

Question 3

A drift monitor runs a χ² test on 50 million rows per day for each feature and alerts at p<0.01p<0.01. It alerts on most features every day, yet the model's accuracy is stable. What is the best fix?

  1. Lower the level to p<0.0001p<0.0001
  2. Alert on an interpretable effect size, such as the L∞L_\infty distance between category frequencies, with thresholds tied to what the model is sensitive to
  3. Sample 1,000 rows per day so the test loses power
  4. Stop monitoring inputs and wait for labels
Show the answer

B. Alert on an interpretable effect size, such as the L∞L_\infty distance between category frequencies, with thresholds tied to what the model is sensitive to

At this scale every real but trivial difference is significant; a stricter level only postpones the problem. An effect-size threshold asks whether the shift is big enough to matter, and keeps the full data.

Question 4

Under the conditions of Perdomo et al.'s theorem, repeated retraining converges to θPS\boldsymbol\theta_{\mathrm{PS}}. What can you say about its performative risk?

  1. It is the minimum possible: stable points are performative optima
  2. Nothing: stable points can be arbitrarily bad
  3. It is not necessarily optimal, but if the loss is LzL_z-Lipschitz in zz, the stable point lies within 2Lzε/γ2L_z\varepsilon/\gamma of every performative optimum
  4. It equals the risk of the first deployed model
Show the answer

C. It is not necessarily optimal, but if the loss is LzL_z-Lipschitz in zz, the stable point lies within 2Lzε/γ2L_z\varepsilon/\gamma of every performative optimum

A stable point is optimal for the distribution it induces, not across all the distributions other models would induce. Strong convexity and ε\varepsilon-sensitivity keep the two notions close: ∥θPO−θPS∥≤2Lzε/γ\norm{\boldsymbol\theta_{\mathrm{PO}}-\boldsymbol\theta_{\mathrm{PS}}}\le2L_z\varepsilon/\gamma.

Further reading

  • D. Sculley, G. Holt, D. Golovin, E. Davydov, T. Phillips, D. Ebner, V. Chaudhary, M. Young, J.-F. Crespo & D. Dennison, "Hidden technical debt in machine learning systems," Advances in Neural Information Processing Systems 28 (2015).
  • E. Breck, S. Cai, E. Nielsen, M. Salib & D. Sculley, "The ML test score: a rubric for ML production readiness and technical debt reduction," IEEE International Conference on Big Data, 1123–1132 (2017).
  • E. Breck, N. Polyzotis, S. Roy, S. E. Whang & M. Zinkevich, "Data validation for machine learning," Proceedings of Machine Learning and Systems 1 (2019).
  • G. Lorden, "Procedures for reacting to a change in distribution," Annals of Mathematical Statistics 42(6), 1897–1908 (1971).
  • J. C. Perdomo, T. Zrnic, C. Mendler-Dünner & M. Hardt, "Performative prediction," ICML (2020).