05 / 16 · Data
Features and training–serving skew
Why a feature can take one value in training and another in serving: skew from code paths, data and time, point-in-time correct joins that keep the future out of training rows, logging served features, and feature stores with offline and online stores.
Data pipelines and orchestration · Data quality, validation and versioning · Data, features and leakage
On this page 6
At training time, a query can see a corrected feature value that did not exist when the original prediction was made. The row carries an old event timestamp, so a join that filters only by event time accepts it. The model is then evaluated on a better-informed world than the one it will encounter online.
The preview service gives us a small way to inspect this error. Its feature records below are independently authored; no learner data, churn dataset or production model is used. We will compare three joins and count changed decisions without claiming a measured model-accuracy improvement.
Share a feature definition and identify its state#
Two pieces of code can both be called contrast while computing different quantities. One subtracts the minimum before scaling, another divides the raw value by its maximum. Both return numbers in the expected range and pass a basic schema check. A model trained on one definition has no reason to interpret the other correctly.
Keep the transformation definition and its fitted state together. A normalization function without its training mean is not the complete feature. A categorical encoder without its vocabulary cannot assign the same meaning to a column. Version the state that changes interpretation, not merely the function name.
A shared implementation reduces one source of divergence, but it does not make the two paths identical by itself. The same code applied to differently timed, filtered or authorized inputs can produce different values. Testing feature equality must therefore identify the inputs as well as the code.
Training–serving skew has several routes#
Here, skew means a relevant mismatch between the features represented in training/evaluation and those available to the serving computation. Martin Zinkevich’s Rules of Machine Learning discusses discrepancies in processing, changing data and feedback, and recommends observing the actual served features. Our case isolates timing while keeping the transformation simple.
A model can also lose quality because the population changed even when the two paths agree perfectly. Conversely, the two paths can disagree before any outcome labels arrive. Keep feature-consistency observations separate from estimates of predictive quality. Both matter, but they answer different questions.
A different computation#
Suppose a fitted transform centers contrast by the training mean. In our three correct historical values, , the mean is . The centered values are approximately . A serving path that instead subtracts 0.5 shifts every feature. Recomputing the mean from each request batch would make a card’s representation depend on its neighbours.
The exact mean is an artifact of the specified fit population. Freeze it with the release and use it on later inputs. If a new population justifies a new normalization, evaluate that change as a candidate; do not silently mutate the state behind the same release identity. This example is arithmetic, not a recommendation that centering is sufficient for preview classification.
A different input population#
An offline dataset may omit records whose metadata was missing, while the online service must handle them. A training query can join a rich analytical table unavailable in the low-latency path. A cache may hold older values than a historical reconstruction assumes. None of these mismatches is corrected by importing the same Python function.
Define the eligible population, missingness policy, freshness and fallback. If a required feature is absent, return a specified missing state or choose a separately evaluated fallback. Substituting a default silently changes the model’s effective input distribution. Log which path was used so later evaluation can separate the cases.
Information from the future#
A timestamp can describe when an event happened, when the source learned about it, or when a pipeline published a derived value. Those are different facts. A late correction may legitimately describe an old event while still being unavailable to an earlier decision.
For each prediction, ask what the executing system could actually have read at that time. A historical label may arrive later and still be a valid target. A feature derived from that label would be leakage if it is presented as an earlier input. The same timestamp field cannot silently serve both purposes.
Join on event time and availability#
Use the following original feature records. Hours share one agreed origin. Availability is when the value became readable by the hypothetical serving path, not merely when a source eventually wrote its retrospective event date.
| Card | Event hour | Available hour | Contrast |
|---|---|---|---|
| A | 8 | 8 | 0.2 |
| A | 8 | 20 | 0.9 |
| A | 25 | 25 | 0.4 |
| B | 7 | 7 | 0.7 |
| B | 9 | 15 | 0.1 |
The second A row corrects the earlier event’s value, but becomes available only at hour 20. B’s event at hour 9 arrives at hour 15. We want to reconstruct decisions for A at hour 10, B at hour 10 and A at hour 30.
First filter by entity and require both event_hour <= prediction_hour and available_hour <= prediction_hour. Among eligible rows, choose the greatest event hour and, for a correction at that event hour, the greatest available hour. The ordering rule is explicit. The selector accepts identical repeats and rejects different values at the same eligible event/availability key, rather than choosing by input row order. A source permitting such changes would need an additional revision key.
| Decision | Available historical join | Event-time-only join | Latest value now |
|---|---|---|---|
| A at hour 10 | 0.2 | 0.9 | 0.4 |
| B at hour 10 | 0.7 | 0.1 | 0.1 |
| A at hour 30 | 0.4 | 0.4 | 0.4 |
For A at 10, the corrected 0.9 has a suitable event hour but an impossible availability hour. For B at 10, the 0.1 event occurred earlier but had not arrived. At A’s hour-30 decision, the event at 25 is already available and wins over the correction of the older event.
If a declared rule sends a card to review when contrast is below 0.5, the event-time-only join disagrees with the available-history join on two of three decisions. This counts inconsistent inputs to a fixed rule. It does not measure real repair need or prove that the rule is a good classifier.
The core selection is small enough to execute directly:
rows = [("A", 8, 8, 0.2), ("A", 8, 20, 0.9),
("A", 25, 25, 0.4), ("B", 7, 7, 0.7),
("B", 9, 15, 0.1)]
def historical(card, hour, ttl=None):
eligible = [r for r in rows if r[0] == card
and r[1] <= hour and r[2] <= hour
and (ttl is None or hour - r[1] <= ttl)]
seen = {}
for row in eligible:
key = (row[1], row[2])
if key in seen and seen[key] != row[3]:
raise ValueError("Conflicting values for the same feature clock key")
seen[key] = row[3]
return max(eligible, key=lambda r: (r[1], r[2]))[3] if eligible else None
queries = [("A", 10), ("B", 10), ("A", 30)]
print([historical(*q) for q in queries])
print([historical(*q, ttl=4) for q in queries])
Executed output:
[0.2, 0.7, 0.4]
[0.2, 0.7, None]
The four-hour freshness limit makes A’s hour-30 feature too old: its event hour is 25. TTL is measured relative to each historical prediction, not the day on which the training query runs. Whether freshness should refer to event age, publication age or another domain clock must be part of the contract. A newly published correction does not necessarily make the underlying observation recent.
Feast’s current point-in-time guide explains both backward event-time retrieval with TTL and an optional created-timestamp availability constraint. The latter relies on a meaningful created timestamp and support from the selected offline store. Our code implements the stated two-clock policy directly; it is not a test of Feast or a promise that any store configuration provides identical semantics.
Compare with the feature that was actually served#
A reconstructed history can be wrong because the source lacks an availability timestamp or because the online cache was stale. Where collection and retention permit it, keep a controlled sample of actual served features with request time, release identity, feature version, freshness and fallback status. Compare reconstructed values against that evidence.
Use the same comparison boundary on both sides. A raw scanner statistic should not be compared with a normalized model input without applying the recorded transform. For approximate numeric kernels, set a justified tolerance; for entity keys and categories, a tolerance is generally not meaningful. Record mismatches by reason rather than collapsing all fields into one average error.
Sampling also needs a definition. Logging only successful requests hides the cases where missing features caused a fallback or failure. Record the inclusion rule and avoid exposing raw documents merely to make debugging convenient. An access-controlled minimal feature record may provide the needed evidence with less retained content.
When a mismatch is found, preserve a permitted minimal case and trace it through input selection, transformation state and caching. A change to the training pipeline can make a future model robust to an intentional serving limitation, but changing the evaluation data retrospectively must not erase the fact that an earlier report used unavailable information.
Feature stores organize a contract that still needs checking#
A feature store can register definitions, provide historical retrieval and serve recent values. An offline store is optimized for large historical joins; an online store for timely lookup. Materializing from one to the other creates a freshness and synchronization boundary, not an identity guarantee.
Choose ownership for feature definitions and a version policy for breaking changes. Adding a category changes the encoder state; changing a window from one day to one week changes the meaning even if the column retains its name. Consumers need an explicit migration or a pinned compatible version. A catalog entry should identify its source and availability rule, not merely describe a business-friendly label.
A point-in-time join is necessary for many training datasets but not sufficient to establish no leakage. A value can already incorporate future information before its timestamp is assigned. A source can backdate availability incorrectly. Audit how the value was computed, not only the SQL predicate or feature-store switch used to retrieve it.
Feature sharing can reduce duplicate transformations while increasing the number of dependent models. A correction that helps one consumer can break another’s assumptions. Inspect affected consumers and retain an old version when a migration needs evidence. This is a consequence of shared meaning, rather than a reason to duplicate every feature implementation.
What changed#
The correction no longer travels backward into the hour-10 decision. The feature value now has both an event-time meaning and an availability boundary. A fixed rule exposes two changed decisions, while the freshness example shows why a missing result may be the correct historical answer.
Limitations#
Five rows cannot establish correctness of a production feature platform. The fixture assumes accurate clocks, a total correction order and recorded availability. It does not simulate clock skew, transactions, cache propagation or concurrent writes. No model was trained and no outcome accuracy is claimed. A historical join cannot reconstruct information that was never logged or has been lawfully deleted.
What to retain#
Version feature code and fitted state. Distinguish input mismatch from outcome degradation. Constrain historical inputs by both event time and availability when required. State freshness and correction rules. Compare a permitted sample against actual served inputs. A feature store supports those contracts but cannot choose them for the product.
Reproduce the example#
The features function in the original Python source checks all three joins, the freshness limit, decision disagreements and centering arithmetic. Saved results preserve the complete fictional inputs. The program uses no external package, dataset or feature store.
Next#
Experiments and the model registry connects these input identities to a particular training run, evaluated artifact and deployed version.
References#
- Martin Zinkevich. Rules of Machine Learning, Google, read 13 November 2026: training–serving skew and rules 29–31. The preview cases and code are independent; no production example or result from the guide is reused.
- Feast contributors. Point-in-time joins, read 13 November 2026: event-time TTL and created-timestamp filtering, including availability/support caveats. No driver records, images, feature-view code or API example copied.