Sub topic 14
TTL, Staleness, and Keeping Training and Serving Consistent
Prerequisites: you should understand Python DataFrames, feature views, historical retrieval, materialization, and online retrieval in Feast. You should also know that a feature is an input value used by a machine learning model.
The working model
A feature store usually keeps two representations of a feature:
- The offline store contains historical values used to build training data.
- The online store contains recent values used for low-latency inference.
A feature can be correct in the offline store but still be unavailable or stale online. A model then sees different data during training and serving. This difference is called training-serving skew.
A feature's freshness is how recently its value was computed or received. A feature is stale when it is older than the application can safely use.
A time to live (TTL) defines how long a feature value remains valid relative to its event time. In Feast, a feature view can specify a TTL:
from datetime import timedelta
from feast import FeatureView
driver_stats_fv = FeatureView(
name="driver_hourly_stats",
entities=[driver],
ttl=timedelta(days=1),
schema=[
Field(name="conv_rate", dtype=Float32),
Field(name="acc_rate", dtype=Float32),
Field(name="avg_daily_trips", dtype=Int64),
],
online=True,
source=driver_stats_source,
)With a one-day TTL, Feast does not treat a value older than one day as valid for the feature view's time-based retrieval rules. The TTL is not a scheduler. It does not create new values. Your pipeline must still compute and load fresh data.
Why training and serving can disagree
Historical retrieval uses an entity row's timestamp. For each training example, Feast selects a feature value that was available at that time and is within the allowed validity period.
Online retrieval usually returns the latest value that has been materialized for an entity. Materialization copies data from the offline source into the online store. If materialization runs only once per day but the model expects hourly data, online values may be too old.
flowchart TD
A[Offline source] --> B[Historical point-in-time retrieval]
A --> C[Materialization job]
C --> D[Online store]
D --> E[Online inference]
B --> F[Training data]
F --> G[Model]
G --> EFreshness checks and common errors
| Problem | Result | Prevention |
|---|---|---|
| Materialization has not run | Online values are missing or old | Schedule and monitor materialization |
| Event timestamps are wrong | Historical joins use invalid values | Preserve source event time |
| TTL is longer than the business limit | The model accepts stale data | Set TTL from the feature's real use case |
| Training uses unavailable future data | Offline metrics look too good | Use point-in-time-correct retrieval |
A TTL should reflect business meaning. A delivery driver's location may become invalid within minutes. A driver's long-term average may remain useful for days. Do not use one TTL for every feature simply because it is convenient.
Track the age of online values, materialization delay, missing-value rates, and differences between offline and online feature distributions. Alert when these measures exceed limits defined for the model.
Choosing a consistency policy
For every feature, document:
- the maximum acceptable age;
- how often the feature is recomputed;
- how it enters the online store;
- what the model should do when it is missing or stale;
- which event timestamp the offline join must use.
A strict policy can reject requests when required features are stale. A fallback policy can use a cached value or a default, but defaults can change model behavior. The policy should be tested with delayed data, missing entities, and failed materialization jobs.
Exercise
A feature has a one-hour TTL, but materialization runs every six hours. Is the feature guaranteed to be fresh online? Why?
Show answer
No. The TTL describes validity, but it does not run materialization. The online store can remain stale or empty between materialization jobs.