Training–serving skew

In one sentence

The model sees different data or logic in production than it saw in training, so quality drops silently with no error. Fix it with one shared transformation path, logged serving features and automated skew checks.

Analogy: A pilot trained in a simulator whose altimeter reads feet flies a plane whose altimeter reads meters. Every skill is right; every decision is wrong.

Serving computes features once and logs them; training learns from exactly what production saw, and a skew check compares the two continuously.

How it works

  • Two code paths are the classic cause: a Python feature re-implemented in Go with a different null default.
  • Time-travel leakage: training rows include information that did not exist yet at prediction time.
  • Preprocessing and freshness skew too: another tokenizer version, other normalization stats, or a daily cache at serving.
  • A parity check recomputes logged requests offline; over ~1% of rows disagreeing means a bug, not noise.
  • LLM analog: evals on clean questions miss production typos and long chats, so sample eval cases from real traces.

Check yourself

Answer to mark it learned; your answers aren't scored.

A pricing model looks great offline, but conversion drops 4% in production with no errors. A parity check shows distance_km disagrees on 38% of rows: Spark computes route distance, the Go backend computes straight-line distance. Best lasting fix?

Go deeper

Full explanation

Training–serving skew is any difference between the data or code a model saw in training and what it receives in production. The model still returns a confident prediction with HTTP 200; only quality drops, so nothing alerts.

Common causes

  • Two code paths: features written in Python or SQL for training and re-implemented in Java or Go for serving. A different null default, log base or time unit is enough.
  • Time-travel leakage: training rows include information that did not exist at prediction time, like a value joined from today's table or a field filled in after the outcome.
  • Preprocessing mismatch: different normalization stats, vocabulary, tokenizer version or image resize.
  • Stale or missing features: training used fresh values; serving reads a daily cache, or falls back to defaults on timeout.

Fixes, best first

  1. One transformation code path imported by both sides, or baked into the model graph.
  2. Log features at serving time and train on those logs (Google's Rules of ML #29).
  3. A Feature stores with point-in-time joins.
  4. Automated checks: per-feature distribution comparison, plus recomputing a sample of logged requests offline to diff values.

LLM analog: evals on clean questions with hand-picked context, while production gets typos, long chats and real retrieval. Sample evals from production traces and run them through the production prompt code.

Code Feature parity check: logged online values vs offline recompute
pythonFeature parity check: logged online values vs offline recompute
import numpy as np
import pandas as pd

FEATURES = ["distance_km", "user_orders_30d", "avg_basket_usd"]

# What the model actually saw in production, logged at serving time
online = pd.read_parquet("serving_feature_log/2026-11-05.parquet")
# The same requests pushed through the TRAINING feature code
offline = recompute_features(online[["request_id", "user_id", "ts"]])

df = online.merge(offline, on="request_id", suffixes=("_on", "_off"))
for f in FEATURES:
    a, b = df[f + "_on"].to_numpy(), df[f + "_off"].to_numpy()
    bad = ~np.isclose(a, b, rtol=1e-3, equal_nan=True)
    rate = bad.mean()
    if rate > 0.01:  # >1% of rows disagree: a code-path bug, not noise
        i = np.flatnonzero(bad)[0]
        print(f"SKEW {f}: {rate:.1%} rows differ, e.g. online={a[i]} offline={b[i]}")
Real example

A ride-pricing model trains on distance_km computed in Spark from GPS traces; the mobile backend re-implements it in Go as straight-line distance. Offline the model looks great; in production conversion drops 4% and nobody can explain it for two weeks. A parity check on 10,000 logged requests shows distance_km disagrees on 38% of rows, by ~30% on average. The team moves the computation into one shared service, logs the features the model actually receives, and retrains on those logs. The next skew is caught by the daily parity job before launch.

Trade-offs +3 · −3

+ You gain

  • Logging served features makes training data match production by construction.
  • A shared transform deletes a duplicate codebase along with its bugs.
  • Parity checks catch skew before launch, not after a two-week revenue dip.

− You pay

  • Log-and-train is slow to start: a new feature has no history until weeks of logs accumulate.
  • Sharing code across languages is hard; it often means a feature service that adds latency and ops.
  • Feature logs at serving volume cost storage and need PII handling.

Use it when

Check before every launch and after any change to features, preprocessing or data sources. Mandatory when training and serving are owned by different teams or written in different languages.

Avoid it when

Don't blame skew for every online drop: if live and training distributions match and parity checks pass, look at drift, feedback loops or an offline metric that doesn't reflect the business.

Numbers to know 3
  • Google's Rules of ML #29: log the features used at serving and train on them; #32: reuse code between training and serving.
  • Rule of thumb: in a parity check, more than ~1% of rows disagreeing on a feature means a code-path bug, not noise.
  • TFDV flags categorical skew by L-infinity distance between training and serving distributions (its guide uses a 0.01 threshold); Jensen-Shannon divergence also covers numeric features.
Common pitfalls 4
  • Validating only on offline data produced by the same buggy pipeline the model was trained on.
  • Different handling of missing values: training drops nulls, serving fills 0.
  • Building training features from the current snapshot of a mutable table (Rules of ML #31).
  • LLM: evaluating with a notebook prompt that differs from the deployed one, or the wrong chat template on a self-hosted model.
Interview questions 2

Answer out loud first, then reveal.

Offline AUC is 0.91 but the model performs far worse online. How do you debug it?Show answer

I suspect skew or leakage before I blame the model. First, leakage: does any feature use information unavailable at prediction time, like a join on today's table? A suspiciously high offline score is a hint. Second, parity: I take a sample of logged production requests, recompute their features with the training code and diff value by value. Third, distributions: compare live inputs with the training set per feature. If all three are clean, I look at drift and at whether the offline metric matches the business outcome. Long term, I log served features and train on them.

What's the LLM equivalent of training–serving skew?Show answer

Eval–production skew. Teams evaluate with clean single-turn questions, hand-picked context and a notebook prompt, while production has typos, long conversations, real retrieval results, a different system prompt and truncated context. The eval says 92% and users disagree. The fix mirrors classic ML: sample eval sets from production traces, run them through the exact production prompt-assembly and retrieval code, and for self-hosted models make sure the chat template and tokenizer match what the model was tuned with.