Anatomy of a Production ML System
In a notebook, "the model" is one object: you fit it and call predict. In production, the same prediction depends on a chain of systems owned by different people: where the raw data comes from, the code that turns it into features, the job that trained the model, the file it was saved to, the service that loads it, the request that reaches the service, and the log that records what happened. A wrong answer can start in any link. This lesson names the links, shows the two bugs that most often break them (training-serving skew and time-travel in features), and sets out which lesson of the course handles each part.
The parts
| Part | Its job | What goes wrong | Lessons |
|---|---|---|---|
| Raw data | the source of truth: databases, event streams, files | schema changes upstream, late or missing data | data validation, DVC |
| Feature pipeline | turns raw data into model inputs, the same way for training and serving | training-serving skew, features that peek into the future | this lesson |
| Training pipeline | produces a model from a data version, with tracked parameters and metrics | unreproducible runs, untracked notebooks | pipelines, tracking, reproducibility |
| Model registry | stores versions with their lineage and decides which one serves | wrong version deployed, no way back | registry, rollback |
| Prediction service | loads the model and answers requests (online) or scores tables (batch) | slow, crashes on bad input, unsafe model files | serving, FastAPI, security |
| Prediction log | records inputs, outputs, model version and an id for every prediction | missing ids, so outcomes cannot be joined later | monitoring |
| Monitoring | watches the service, the data and the model's quality | alarms nobody reads, or none at all | drift, retraining |
A feature store is a product that bundles the feature pipeline with an offline store (history, for training) and an online store (latest values, read in milliseconds by the service). Feast, Tecton and the stores built into Databricks, SageMaker and Vertex AI are examples. You do not need one to follow the course, but you need what it provides: one definition of every feature, used in both places.
Training-serving skew
Training-serving skew is any difference between the features a model saw in training and the features it receives in production. The most common cause is two implementations of the same feature: a pandas notebook for training and a hand-written function in the service. Here the training data stores income in thousands, but the service team passes raw dollars, as the application form does:
import numpy as np
from sklearn.linear_model import LogisticRegression
rng = np.random.default_rng(0)
n = 1000
income_k = rng.normal(60, 20, n).clip(10, None) # income in thousands
debt_ratio = rng.uniform(0, 1, n)
y = (0.04 * income_k - 3 * debt_ratio + rng.normal(0, 0.7, n) > 1).astype(int)
X_train = np.column_stack([income_k, debt_ratio])
model = LogisticRegression().fit(X_train, y)
applicants = np.array([[25.0, 0.8], [60.0, 0.4], [110.0, 0.1]]) # thousands, as in training
print("training units :", model.predict(applicants))
skewed = applicants.copy()
skewed[:, 0] *= 1000 # the service sends dollars
print("serving units :", model.predict(skewed))
print("approval rate in training data:", round(float(y.mean()), 3))training units : [0 1 1]
serving units : [1 1 1]
approval rate in training data: 0.454
With the units the model was trained on, the three applicants get 0, 1 and 1: the low-income, high-debt applicant is refused. With dollars, an income of 25,000 looks like 25,000 thousand, and every applicant is approved, in a population where only 45 % were approved in training. Nothing raises an error: the input has the right shape and type. The bug only shows as a strange prediction distribution, which is why monitoring watches the share of each predicted class and data validation checks value ranges on the way in.
The cure is structural, not careful typing: ship the preprocessing with the model. A scikit-learn Pipeline saved as one object, an ONNX graph that contains the scaler, or a feature store that serves the same computed feature to both sides. If the service must compute a feature itself, put the function in a shared library with a unit test that runs it on rows from the training table and compares.
Point-in-time correctness
The second classic bug happens in the training data itself. Suppose a model predicts on 1 March whether a customer will default, and one feature is "number of late payments". If the training table joins each loan to the customer's current number of late payments, it includes payments that were late after the prediction date: information the model will never have in production. This is data leakage through time, and it makes offline scores look better than anything the deployed model can reach.
A point-in-time join takes, for each training example, the latest feature value known at or before that example's timestamp. pandas does this with merge_asof:
import pandas as pd
events = pd.DataFrame({ # when each prediction would have been made
"customer": ["a", "a", "b"],
"ts": pd.to_datetime(["2026-03-01", "2026-06-01", "2026-03-01"]),
"defaulted": [0, 1, 0],
})
late_payments = pd.DataFrame({ # feature history: value valid from ts on
"customer": ["a", "a", "a", "b", "b"],
"ts": pd.to_datetime(["2026-01-01", "2026-04-15", "2026-05-20", "2026-01-01", "2026-07-01"]),
"late": [0, 2, 5, 1, 3],
})
latest = late_payments.sort_values("ts").groupby("customer").tail(1)[["customer", "late"]]
naive = events.merge(latest, on="customer")
pit = pd.merge_asof(events.sort_values("ts"), late_payments.sort_values("ts"), on="ts", by="customer")
print("naive join (today's value):")
print(naive.to_string(index=False))
print("point-in-time join:")
print(pit.sort_values(["customer", "ts"]).to_string(index=False))naive join (today's value):
customer ts defaulted late
a 2026-03-01 0 5
a 2026-06-01 1 5
b 2026-03-01 0 3
point-in-time join:
customer ts defaulted late
a 2026-03-01 0 0
a 2026-06-01 1 5
b 2026-03-01 0 1
On 1 March customer a had 0 late payments, not 5, and customer b had 1, not 3. The naive join gives the March rows values from April to July. A model trained on it learns "many late payments" from rows where the payments had not happened yet. Feature stores do point-in-time joins for you; without one, every training query needs an "as of" condition.
Hidden technical debt
Sculley and colleagues at Google described ML-specific technical debt in a 2015 paper ("Hidden Technical Debt in Machine Learning Systems"). Several of their categories show up again in this course:
- Entanglement (CACE: changing anything changes everything). Change one feature's scaling and every learned weight shifts. Version the whole bundle (data, features, model) together.
- Undeclared consumers. Another team reads your model's scores and builds on them; your next release breaks them silently. Publish a versioned API and a model signature.
- Data dependencies. An upstream table changes its meaning; the code still runs. Validate data and monitor drift.
- Feedback loops. A model's predictions change the data it will be trained on next (a recommender shows only what it already likes). See retraining.
- Glue code and pipeline jungles. Scripts that move data between tools. Replace them with declared pipelines.
- Configuration debt. Hundreds of settings with no review. Keep configuration in version control and track it with each run.
Pitfalls
- Reimplementing features in the service. Every reimplementation is a chance for skew. Ship the transform with the model or share one tested function.
- Joining features "as of now" for training. Use point-in-time joins; otherwise offline metrics are inflated.
- No prediction ids. Without an id in the log, true outcomes that arrive weeks later cannot be matched to the prediction, and model quality can never be measured.
- Treating the model file as the product. The product is the model plus its feature code, data version, configuration and the service around it.
Practice
- A fraud model scores 0.95 AUC offline and 0.70 in production from the first day, and the input distributions in production match the training data. Name two causes from this lesson to check first.
- Why does the skewed example approve all three applicants rather than raising an error?
- In the point-in-time example, what value of
lateshould the row for customerbget ifbhad a prediction on 2026-07-02?
Answers
- Point-in-time leakage in the training table (features that include information from after the prediction time inflate the offline AUC), and training-serving skew in some feature that is computed differently online (the marginal distributions can match while the per-row values are paired wrongly, for example a feature taken from the wrong row or time window).
- Dollars are a valid float array of the right shape, so the model computes a score; the income coefficient is positive, and incomes 1,000 times larger push every score far into the "approve" side. Models do not check units: data validation and monitoring must.
- 3: the latest value known at or before 2026-07-02 is the one recorded on 2026-07-01.
Test yourself
What is training-serving skew?
- The model is larger in production than in training
- A difference between the features the model saw in training and those it receives in production
- Serving uses a GPU and training a CPU
- The training set is unbalanced
Which fix removes the most common source of training-serving skew?
- Retraining more often
- Shipping the preprocessing together with the model (one Pipeline object, ONNX graph or shared feature definition)
- Using a bigger model
- Logging fewer features
A training table joins each loan to the customer's current number of late payments. Why is that a problem?
- It is slow
- It leaks information from after the prediction time, so offline scores are better than production can be
- It removes rows
- It changes the label
Why should every logged prediction carry an id?
- For load balancing
- So the true outcome, which may arrive weeks later, can be joined to it to measure model quality
- To compress the log
- Because HTTP requires it