Feature Stores: Online vs Offline Features and Training-Serving Skew
Feature stores explained: offline and online stores, point-in-time correct training data, streaming features and how they prevent training-serving skew.
A feature store is the system that computes, stores and serves the input features for machine learning models, so the same feature definitions are used when building training data and when making live predictions. It usually has an offline store for large historical datasets and an online store for low-latency lookups at prediction time, plus a registry of feature definitions. Its main job is preventing training-serving skew: a model trained on one version of a feature and served another.
Why teams build one
- Training-serving skew: a data scientist computes "orders in the last 7 days" in a notebook with SQL; an engineer reimplements it in the serving path in Java with a subtly different window. The model performs well offline and poorly in production.
- Point-in-time leakage: a training row for a prediction made on 1 March accidentally includes data from 5 March. The model learns from the future and offline metrics lie.
- Duplicated work: five teams compute the same customer features five ways.
- Latency: live prediction needs features in milliseconds, which the warehouse can't serve.
Architecture
| Component | Role | Typical storage |
|---|---|---|
| Registry | Feature names, entity keys, owners, transformation code, freshness | Metadata database, version control |
| Offline store | Full history of feature values with timestamps, for training and batch scoring | Lakehouse tables, warehouse |
| Online store | Latest value per entity, read in a few milliseconds | Key-value store such as Redis or a wide-column database |
| Materialisation jobs | Compute features and write them to both stores | Spark, SQL, stream processors |
Point-in-time correct training data
To build a training set, you start from labelled events, each with an entity key and a timestamp (a transaction and whether it turned out to be fraud). For each event, you need each feature's value as of that timestamp, not today's value. That's a point-in-time ("as of") join: for every event, take the latest feature row whose timestamp is at or before the event time.
-- For each labelled transaction, the customer's 7-day order count as it was at that moment
select t.transaction_id, t.label, f.orders_7d
from labelled_transactions t
left join lateral (
select orders_7d from customer_features f
where f.customer_id = t.customer_id and f.feature_time <= t.event_time
order by f.feature_time desc
limit 1
) f on true;Also respect when a feature *became available*, not only when it describes. A daily batch feature for 1 March that lands at 04:00 on 2 March wasn't available to a prediction at 23:00 on 1 March.
Batch, streaming and on-demand features
| Kind | Freshness | Example | Computed by |
|---|---|---|---|
| Batch | Hours to a day | Customer lifetime value, 90-day purchase count | Scheduled Spark or SQL |
| Streaming | Seconds | Transactions in the last 10 minutes on this card | Stream processor with windows |
| On-demand | At request time | Distance between this request's location and home address | The serving path, from request data |
Streaming features need the same windows and watermarks care as any stream job, and the offline store must record the same values the online store served, or backfill them identically.
Serving considerations
- Latency budget: a model call with a 50 ms budget might allow 5-10 ms for feature lookups, so batch lookups by entity key in one round trip.
- Freshness and defaults: define what the model gets when a feature is missing or stale, and train with the same default.
- Log what was served: logging features at prediction time gives exact training data for the next model and makes skew measurable.
- Hot entities: a popular item or merchant can become a hot key in the online store; cache it.
Where it’s used
Streaming velocity features (transactions per card in 10 minutes) and batch profile features are looked up together in a few milliseconds.
User and item features are shared by retrieval and ranking models across teams.
Recent supply and demand features per area are served online and logged for retraining.
In an interview
- Name training-serving skew and point-in-time leakage as the problems the store solves.
- Separate offline and online stores and say what technology fits each.
- Explain the point-in-time join, including feature availability time.
- Log served features to build future training data.
Further reading
- Feast documentation: ConceptsFeast (open source)
- Meet Michelangelo: Uber's Machine Learning PlatformUber Engineering Blog