Skip to content

Feature stores and training-serving skew

A feature store holds one definition of each model input, serves its latest value at request time and retrieves the values that held at past timestamps for training. Training-serving skew is the gap that opens when those two paths disagree.

On this page

What it is

A feature is one input to a model: the number of payments on a card in the last minute, a driver's trips so far today. A feature store holds the definition of each feature and its values in two places. The offline store keeps the timestamped history, used to build training sets and to score in batch. The online store keeps the latest value per entity (per card, per driver) for low-latency reads while a request waits. A materialization job copies values from the offline store into the online one, and a push path can update the online value as soon as an event arrives. The Feast documentation (v0.68, the version read for this page) describes the system this way and lists online fraud detection, where a payment is compared against precomputed history, as a typical use.

Training-serving skew is the condition where the input data a model trained on differs from the input data it sees when serving. Google's machine learning course separates two kinds: schema skew, where training and serving data don't follow the same schema, and feature skew, where the engineered values differ because the code that builds them differs. One way that happens: a warehouse query builds the training set, service code builds the serving features, and the two disagree in small ways. One side's window is 60 seconds and the other's is the current calendar minute; one counts the payment being scored and the other doesn't; a missing value becomes 0 on one side and is dropped on the other. The model's offline metrics then describe inputs it won't get in production. Google's Rules of Machine Learning advise checking that the model scores the same in the training and serving environments, and keeping tests on the code that builds examples on both sides.

Point-in-time correctness is the time half of the same problem. A training row is a past event with a label, and the feature values attached to it should be the ones that existed when the event happened. The store's training request is an entity dataframe: entity ids, an event timestamp per row, and any label columns you want to keep. For each row the store looks back from that row's timestamp to the most recent feature row within the feature view's TTL. A row older than the earliest feature row, or more than one TTL past the latest one, gets no value rather than a stale or future one. The TTL is measured from each row's own timestamp, not from when the query runs, so a two-hour TTL on a training set from last year still means the two hours before each event.

Backfills can still leak. By default the as-of join constrains the feature's event timestamp and nothing else. A value recomputed or backfilled later (a corrected count written a week after the fact) carries the original event timestamp, so it can be returned for a training row that predates the moment the value existed. The v0.68 documentation adds a filter_by_created_timestamp option that also requires the value's created timestamp to be at or before the row's timestamp, which approximates what the online store would have served at that moment. It needs a non-null created-timestamp column, and some offline stores don't support it yet and raise an error instead of ignoring it.

GapHow it opensWhat closes it

Feature skew

Different code computes the feature for training and for serving

One job feeds both stores; a test that runs both paths on the same input and compares

Leakage through time

Training rows receive feature values from after the event

An as-of join on the event timestamp; a created-timestamp filter for backfilled values

Freshness gap

The online value lags the stream, or the training log holds a batch value that didn't reach the online store

Push stream values to both stores; materialize on a schedule; measure the lag

Label delay

The label arrives months after the event

Keep the event's timestamp on the row; append the label when it lands; train on windows old enough to be labeled

When to use it

Reach for a feature store when a feature needs history the request doesn't carry (payments on this card in the last minute, the average ticket over 30 days), when the same feature feeds more than one model, or when you serve predictions online and train offline from the same data. The reasons Feast gives for itself are the same list: consistent features across an offline and an online store, point-in-time correct training sets so future data doesn't leak in, and one shared catalog of definitions.

For a count that must be current, such as payments per card in the last minute, the shape is a stream job that consumes payment events, maintains the per-card count, and pushes each update to the online store, while writing the same values to the offline store as a log for training. The push documentation describes that setup and recommends materializing from the offline store to the online one on a schedule, which it says reduces training-serving skew. Our advice: have one job write both stores, so training and serving are fed numbers computed by the same code; what remains is how far the online value lags the newest event, and that lag can be measured and given a budget. For the windowed count itself, see Stream processing and windows.

When the label arrives late, as a chargeback can, landing months after the payment in the scenario this page uses, the training row keeps the payment's own timestamp and card id, and the label column is filled in when the dispute lands. The as-of join then attaches the count as it stood at the payment time, not as it stands today. One consequence: the freshest fully labeled data is months old, so a training set covers a window that has had time to be labeled, and the newest transactions are left out or handled with a separate signal. Rule 8 of the Rules of Machine Learning asks how much a model degrades when it is a day, a week or a quarter old; the answer sets how often to retrain and how closely to watch.

When not to

Scoring in batch. If predictions are produced once a day by the same job that computes the features, there is no online path for an online store to serve. An as-of query in the warehouse does the point-in-time join, and a separate serving store adds cost without closing a gap. Add the store when a request has to wait for the prediction.

Features that come from the request. If each feature can be derived from the payload itself (amount, currency, hour of day, whether the device matches the account), compute them in one function shared by the training example builder and the serving path. There is no history to look up, so there is nothing for a store to hold. What you still want is the comparison test: run both paths on the same input and check that the outputs match.

One model, a small team. Log the feature vector the serving code used, keyed by request id, and train on those logs. Training then sees what serving saw, with less machinery. The costs are time and flexibility: you wait until enough logged traffic has labels, and a feature added today has no history until you backfill it. A store also does less than its name suggests. The Feast documentation says the project is not an ETL system, does not manage streaming pipelines, and does not version datasets or labels, so the pipelines that compute features and the bookkeeping for training sets stay your job.

Compared

ApproachHow training gets featuresSkew riskWhen it is the right choice

Two implementations (warehouse SQL for training, service code for serving)

A query over historical tables

High: the two drift apart in windows, nulls and edge cases

A prototype or a one-off analysis, with a comparison test added before anything ships

Shared function on request data

The same function runs over logged requests

Low: one code path, but it reaches just the values present in the request

Features need no history: amount, hour of day, device match

Log at serving, train on the logs

Training reads the vectors serving actually used

Low for existing features; a new feature has no past until backfilled

One or two models, modest traffic, and time to wait for labels

Feature store (offline history plus online store, as-of join)

An as-of join over the offline history, at each row's timestamp

Low when one job feeds both stores; a freshness lag remains to measure

Aggregates over history, features reused across models, online serving

In a picture

pushlogreadlaterlabelPayment eventsStream jobOnline storeOffline historyModel scoresChargebackAs-of joinTraining set
One stream job writes the per-card count to both stores. Serving reads the online value now; the chargeback that arrives months later labels the row, and the as-of join attaches the offline values at the payment's own timestamp.

How to say it in an interview

The common mistake

Quiz

Suppose, as an example, a team builds a fraud training set by joining each card's current 30-day payment count onto two years of labeled transactions. Offline precision looks excellent; in production it comes out far lower. What is the most likely cause?
Suppose, as an example, the per-card count is computed in SQL for training and reimplemented in the serving service, and offline and online scores for the same payments come out different. Which kind of skew is this, and what closes it?
A feature view has a two-hour TTL. A training row's event timestamp is eleven hours after the most recent feature row for that entity. What does the as-of join return for that row?
Suppose, as an example, a chargeback for a payment arrives two months after the payment. What makes it possible to train on that payment correctly?

Questions that use this

Related

Sources

  1. Feast documentation (v0.68): Introduction
  2. Feast documentation (v0.68): Point-in-time joins
  3. Feast documentation (v0.68): Push data source
  4. Google Machine Learning Crash Course: Production ML systems, Monitoring pipelines
  5. Google for Developers: Rules of Machine Learning
Sign in to report a mistake