Sub topic 11
Materializing Features into the Online Store
This chapter assumes that you know Python, pandas, the Feast repository structure, and the difference between batch and online inference. It focuses on moving feature values from an offline source into an online store so that a model can read them with low latency.
What materialization does
Materialization is the process of copying feature values from an offline data source into the online store. The offline source may contain months of historical rows. The online store usually keeps only the latest usable value for each entity and feature.
For example, an offline source might contain hourly statistics for every driver:
| driver_id | event_timestamp | conv_rate | acc_rate |
|---|---|---|---|
| 1001 | 2025-01-01 11:00 | 0.18 | 0.96 |
| 1001 | 2025-01-01 12:00 | 0.21 | 0.97 |
After materialization through noon, the online store should return 0.21 and 0.97 for driver 1001. It is optimized for this key-based lookup, not for scanning the complete history.
flowchart TD
A[Offline feature source] --> B[Materialization job]
B --> C[Apply entity and timestamp rules]
C --> D[Online store]
D --> E[Online inference request]The materialization job uses the feature view definition, entity join keys, timestamps, and the requested end time. It writes values that are available up to that time. A later run can copy newer values.
Run incremental materialization
First, register the repository definitions:
feast applyfeast apply updates the registry. The registry records definitions such as entities, feature views, schemas, data sources, and feature services. It does not usually copy all feature values into the online store.
To copy values through the current UTC time, run:
feast materialize-incremental $(date -u +"%Y-%m-%dT%H:%M:%S")The incremental command is suitable for scheduled jobs. A scheduler might run it every five minutes, every hour, or once per day, depending on how quickly the model needs new features.
The end timestamp is important. Suppose the job runs at 13:00. Values with event timestamps later than 13:00 should not be available yet. This prevents a serving process from reading future data.
Read the materialized values
After materialization, use get_online_features for an inference request:
from feast import FeatureStore
store = FeatureStore(repo_path=".")
online_features = store.get_online_features(
features=[
"driver_hourly_stats:conv_rate",
"driver_hourly_stats:acc_rate",
],
entity_rows=[{"driver_id": 1001}],
).to_dict()
print(online_features)The entity row supplies the join key. Feast uses driver_id to find the corresponding values in the online store. The returned values are the latest materialized values, subject to the feature view's time-to-live setting.
Materialization does not guarantee that a value exists. A key may be new, the source may not contain a recent row, or the value may have expired. Production inference code should define behavior for missing or stale features, such as using a default, rejecting the request, or selecting a fallback model.
Incremental versus full loading
Incremental materialization loads data after the previous materialization boundary and up to a chosen end time. It limits repeated work and is usually the normal production pattern.
A full materialization reloads a broader time range. It can help after creating a new online store or repairing missing values, but it reads more data and can increase load on the offline source.
For reliable jobs:
- Make the job repeatable. A retry should not produce conflicting values.
- Monitor the latest materialized timestamp.
- Alert when source arrival or materialization falls behind.
- Keep the feature view definition consistent between training and serving.
- Check that entity keys have the same type and meaning in both paths.
Exercise
Why does feast apply need to run before materialization, and what does get_online_features return afterward?
Show answer
feast apply registers the current entities, feature views, schemas, and sources. Materialization then uses those definitions to copy eligible values into the online store. get_online_features returns the latest available materialized values for the requested entity keys and features.