Learning path: Data and Features in Production · Step 6 of 8
Training-Serving Skew: Same Model, Different Inputs, and How to Detect It
Offline the model is great, live it gets worse, and nothing crashes. What training-serving skew is, the three usual causes, how it differs from drift, and how to detect it, test the alert and roll back.
What you will learn
- Define training-serving skew: the same record gives one feature value in training and another in serving
- Name the usual causes: transforms, timestamps and fill rules that differ between pipelines
- Tell skew apart from drift and from label leakage
- Detect it with live distributions and replay, test the alert on purpose, and recover with feature versions
Before you start
- Data Validation and Schema Checks
- Point-in-Time Correctness
Take a food delivery app. A model predicts when your order will arrive. In the offline test it's off by about 4 minutes on average. The team ships the same model, and soon it's off by 11 minutes. (These numbers are a made-up example.)
No crash, no alert. Every call still returns 200. Nothing is broken, yet the answers are wrong.
That's the classic interview question too: offline accuracy is high, live predictions keep getting worse. What is training-serving skew, and how would you detect it?
The short answer
Skew means the same input gives one feature value in training and another in serving. A feature is just a number the model reads. Same model, different inputs.
- Check the feature transforms and the timestamps, side by side.
- Watch the live distributions against the training ones.
- Version your features, so you can roll back to the last good one.
A simulator whose dials read differently
Think of a pilot in a simulator. The altitude dial reads in feet: 10,000 feet, and the pilot passes every test. Then comes the real plane. Same pilot, but this dial reads in metres, so at the very same height it says 3,048. That looks far too low, so the pilot pulls up. A perfect reaction, to a wrong reading.
The pilot is the model. The simulator is training, the real plane is serving, and the dial is a feature. The pilot didn't forget anything. The dials just read differently.
One order, two sets of numbers
Back to the delivery app. One order goes through two pipelines: the code that turns raw data into features for training, and the code that does it at serving time.
- Distance, a transform problem. Training stores 5 kilometres. Serving sends miles, so 3.1.
- Hour, a timestamp problem. An order at 1 pm. Training saved 7, in UTC; serving sends 13, in local time.
- A blank prep time, a fill rule problem. Training filled in the average, 12 minutes. Serving just sends 0.
The model gets numbers it never learned from, and nothing warns it. You can see the same thing with real numbers in Data Validation and Schema Checks: a serving helper that turns car weight into kilos took test RMSE from 2,068 to 5,067, and most of those cars still passed the schema.
The trap: calling it drift and retraining
Here's where weak answers go wrong. Live got worse, so "it must be drift, let's retrain". But retrain on the same pipeline, and serving still sends different numbers, so the same gap comes back.
| What changed | Do the pipelines agree on one record? | |
|---|---|---|
| Drift | The world changed | Yes |
| Skew | The pipelines disagree | No |
| Label leakage | A training feature secretly held the outcome, so the offline score was false | Not the question: the offline score was never real |
Same symptom, different bugs. Rule out label leakage too (see Train-Test Split and Data Leakage and Point-in-Time Correctness).
Catch it before the customer does
- Compare distributions. Plot a feature in training, then the live values on top. With miles instead of kilometres, the whole distance shape slides to the left. Compare live against training feature by feature, and alert when the gap goes past a normal day.
- Replay. Send the same records through both pipelines, and count what share match.
- Test the alert on purpose. Ship a kilometres-to-miles change in shadow mode, where nobody uses its answers. It passes if the alert fires, and rolling back to the last feature version clears it.
An alert you've never seen fire is only a hope.
The follow-up questions
- Is it skew or drift? Replay the same records through both pipelines. If they disagree, it's skew. If they agree, that points to drift.
- How do you stop it coming back? Share one transform between training and serving, or train on the features you logged at serving time. (A feature store is one way to share them; see Feature Stores.)
- A bad feature version is live. What first? Roll back to the version the model was trained on, then fix it.
Before you touch the model, compare the inputs.
Quick recap
| Step | What to do |
|---|---|
| Spot | High offline, low live, nothing crashed: suspect the inputs first |
| Find | Check transforms, timestamps and fill rules side by side |
| Detect | Live vs training distributions, plus replay through both pipelines |
| Prove | Ship a known skew in shadow mode and see the alert fire |
| Recover | Roll back to the feature version the model was trained on |
The pilot didn't forget how to fly. The dial just read differently.
Built this? Share your solution in the StudyEasy AI Community.
Join free on Skool →Data Validation and Schema Checks: Stop Bad Input Before It Reaches the Model
Next →Feature Stores: Offline and Online Stores, and When You Actually Need One
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Machine Learning Engineer: From First Model to ML Engineer
Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (opens in a new tab)Related articles
Python Virtual Environments: One Project, One Toolbox
Why every Python project gets its own virtual environment: two projects that need different versions of requests, python -m venv .venv, activation, pip install and the PyCharm setting that activates it for you.
Git and GitHub Fundamentals: Commits, Branches, Push and Pull
The Git you use every day, on a tiny hello-ml project: commits as save points, the staging area, a branch merged with a fast-forward, then push, clone, pull and pull requests with a teammate.
Testing a FastAPI App with pytest: Three Small Tests
A tiny FastAPI app with a Hello World route and a name route that refuses numbers, three pytest tests that check it, and what happens when the validation is deleted by mistake.
Config and Logging Instead of Hard-Coded Values in ML Training
Take the hard-coded values out of a car price training script: one config.toml read with tomllib, logging with levels and a run id on every line, and secrets read from the environment. Same RMSE, 2195, before and after.