Sub topic 1
Why Feature Stores Exist: Reuse and Training-Serving Skew
Prerequisites
This chapter assumes you can:
- Read Python and pandas code.
- Describe the basic machine learning workflow: build a training set of features and labels, fit a model, then run inference on new data.
- Run commands in a terminal.
- Explain the difference between batch processing (large jobs over stored data) and real-time serving (one request answered in milliseconds).
No Feast code is needed yet. Later chapters build the repository, the feature views and the retrieval calls. This chapter explains the problem they solve.
What a feature is, and where it goes wrong
A feature is a measurable input to a model, such as a driver's average daily trips over the last 30 days. Features are usually derived from raw data (events, transactions, logs) through a transformation. The same feature is needed in two places:
- Training. You compute the feature for many historical rows to build a training set.
- Inference. You compute or look up the feature for one entity, such as one driver, while a request waits for a prediction.
Without shared infrastructure, each place tends to get its own code, its own storage and its own owner. Two problems follow: training-serving skew and duplicated work.
Training-serving skew
Training-serving skew is a difference between the feature values a model saw during training and the values it receives in production, for the same logical feature. The model was fitted to one distribution and is evaluated on another. Accuracy drops, usually without any error message.
Common causes:
- Duplicated logic. A data scientist writes the feature in pandas or SQL. An engineer later rewrites it in the serving language. Small differences creep in.
- Different data sources. Training reads a warehouse table that is cleaned nightly. Serving reads an operational database with raw values.
- Different handling of missing values, time zones, rounding or categorical encodings.
- Different time semantics. Training uses values that were computed after the moment of prediction. Serving cannot, because that data does not exist yet.
The next example shows the first and third causes together. The training code skips missing fares. The hand-rewritten serving code counts them as zero.
import pandas as pd
# Raw fare events for driver 1; one fare was never recorded.
fares = [10.0, None, 20.0]
# Training pipeline (pandas): mean() skips missing values.
train_df = pd.DataFrame({"driver_id": [1, 1, 1], "fare": fares})
train_avg = train_df.groupby("driver_id")["fare"].mean().loc[1]
# Serving code, rewritten by hand: missing values count as zero.
def serving_avg(values):
cleaned = [v if v is not None else 0.0 for v in values]
return sum(cleaned) / len(cleaned)
serve_avg = serving_avg(fares)
print(f"training value: {train_avg}")
print(f"serving value: {serve_avg}")The training value is 15.0 and the serving value is 10.0. Both functions look reasonable. Nothing raises an error. The model learned from 15.0-style values and now receives 10.0.
The cause is two implementations of one definition. A feature store addresses this by making the definition, and the data it reads, a single shared object.
Feature reuse
The second problem is organizational. In a team with several models, the same signals are needed repeatedly. A fraud model, a pricing model and a churn model may all need "transactions in the last 7 days". Without a shared catalog:
- Each team recomputes the feature, paying for compute and storage several times.
- The copies drift apart, so the "same" feature has different values in different models.
- A new project cannot find out what already exists, so it starts from raw data.
- Ownership is unclear. When an upstream table changes, nobody knows which models break.
A feature store gives features a name, a schema, an owner and a place in a registry. Another team can search the registry, see the entity, types and source, and reference the feature instead of rebuilding it.
What a feature store does
A feature store is a system that manages features as first-class, versioned definitions and serves them consistently to both training and inference. Its main responsibilities are:
- Definition. Features are declared once, in code, with their entity, source data, types and freshness rules.
- Registry. The definitions are stored as metadata that people and programs can query.
- Offline access. Large volumes of historical values are retrieved to build training sets, with correct handling of time.
- Online access. The latest value for a given entity is retrieved in milliseconds for inference.
- Synchronization. Values computed from batch data are copied from the historical store into the low-latency store, so both sides draw from the same source.
Feast, the system used in this tutorial, covers these responsibilities. It does not replace your warehouse or your stream processor. It sits on top of them and coordinates how their data is described and served.
The following diagram contrasts the two setups.
Time is the hidden difficulty
Skew is not only about code. It is also about when a value was known. Suppose you train on the label "driver accepted the ride at 12:00" and join a feature "average daily trips" computed at 18:00 that day. The feature includes information from after the event. This is label leakage. The model looks accurate offline, because it saw the future, and fails online, because the future is never available.
A correct training set must use each feature value as it was at the time of each training row. This is called a point-in-time join. Implementing it by hand over large tables is slow and error-prone, so it is one of the strongest reasons to use a feature store. A later chapter covers it in detail.
What a feature store does not fix
- Wrong feature logic. A shared bad definition is still bad. Skew is reduced, not model quality guaranteed.
- Stale data. If values in the online store are not refreshed, serving drifts from training. Freshness rules and refresh jobs are a later topic.
- Changes in the world. Data drift, where real-world distributions shift over time, is a separate problem from skew. Monitoring is still needed.
- Request-time inputs. Values that exist only when a request arrives, such as the current cart total, cannot be precomputed. They need request-time transformations, which are covered later.
When you probably do not need one
A feature store adds a registry, a refresh process and an online database to operate. It pays off when at least one of these is true:
- Several models or teams share features.
- You serve predictions online and also train on history.
- Features depend on time windows, where leakage is a real risk.
- Features come from multiple sources that must be joined consistently.
For a single batch-scoring model that reads one table, a well-tested SQL view or a shared Python module may be enough. Choose the smallest tool that removes your real source of skew.
Common mistakes
- Treating the feature store as a data warehouse. It holds feature values keyed by entity and time, not all your analytical data.
- Computing the "same" feature in two languages. Even with a store, keep each feature's transformation in one place.
- Ignoring timestamps. Features without event times cannot be joined to training rows correctly.
- Skipping the registry. Features that are defined only in notebooks cannot be discovered or reused.
Where this leads
The next chapter shows how Feast splits these jobs between a registry, an offline store and an online store. Later chapters then define the objects (entities, data sources, feature views), build a point-in-time-correct training set, and serve the latest values online.
Exercise
In the example above, training gives 15.0 and serving gives 10.0 for the same driver. Name the root cause, and say how a feature store reduces the chance of this happening.
Show answer
The root cause is that the feature was implemented twice. The training code skips missing fares, and the hand-written serving code treats them as zero. A feature store reduces this by holding one shared feature definition and one source of data that both training retrieval and online retrieval use, so the logic is not rewritten for serving.
Exercise
A team joins a feature that was computed at the end of each day onto training rows timestamped at noon the same day. The model scores very well offline and poorly in production. What is this problem called, and what join approach prevents it?
Show answer
This is label leakage, which comes from using information that was not yet available at prediction time. A point-in-time join prevents it by attaching to each training row the latest feature value from at or before that row's timestamp.