Sub topic 4
Online Features: Latest Values at Low Latency
Prerequisites
This chapter assumes you know Python and pandas and the basic ML workflow of training data, features, labels and inference. It also assumes you have seen the Feast layout from earlier chapters: the registry, the offline store and the online store. Here the focus is the online side: what it stores, how it is read, and what to watch for.
What an online feature is
An online feature is a feature value that a running application reads at inference time. A request arrives, for example "score driver 1001", and the model needs that driver's current conv_rate within a few milliseconds.
Two properties define online features:
- Only the latest value for each entity key is kept. There is no history.
- Access is a key lookup, not a scan. You ask for specific entities and get specific rows back.
An offline query might read months of data for millions of entities. An online query reads one or a few rows and must return fast enough to fit inside the latency budget of the prediction request.
Offline and online access compared
| Aspect | Offline access | Online access |
|---|---|---|
| Typical caller | Training job, batch scoring | Live service handling a request |
| Rows per call | Thousands to billions | One to a few hundred |
| History | Full, with timestamps | Latest value only |
| Latency target | Seconds to minutes | Milliseconds |
| Storage | Warehouse or files such as Parquet | Key-value store such as SQLite, Redis or DynamoDB |
| Feast call | `get_historical_features` | `get_online_features` |
The two stores hold the same features, but they are laid out for opposite workloads. A columnar file is efficient for large scans and poor for single-key reads. A key-value store is the reverse.
Where the data comes from
You do not write to the online store by hand. Feast fills it in one of two ways:
- Materialization copies the newest values from the offline source into the online store. The next chapters cover this in detail. The command is
feast materialize-incremental <end_timestamp>. - Push ingestion writes values directly from an event or stream, bypassing the batch path.
A feature view is only eligible for online serving if it has online=True, as in the example feature view. With online=False, materialization skips the view and get_online_features cannot read it.
The flow looks like this:
Configuring the online store
The online store is chosen in feature_store.yaml. The minimal local setup uses SQLite:
project: driver_project
registry: data/registry.db
provider: local
online_store:
type: sqlite
path: data/online_store.db
offline_store:
type: fileSQLite is a file on local disk. It is good for learning and for tests. It is not designed for many concurrent services on different machines. In production you swap the online_store block for a networked store such as Redis, DynamoDB or Postgres. Your feature definitions and your get_online_features calls stay the same. Only this block changes, and the store-specific connection settings go with it.
What the online store keeps
For each feature view, the online store keeps one row per entity key. If driver 1001 has hourly rows in the offline source, the online store holds the latest one that materialization has seen. Each stored value carries the event timestamp of the row it came from.
Materialization takes the row with the greatest event_timestamp per entity within the window it processes. The created_timestamp_column in the data source breaks ties when two rows share an event timestamp. Without it, which duplicate wins is not defined.
The online store is an overwrite-latest structure. If you run materialization over an old window after a newer one, the newer values should not be replaced by older ones. Feast compares event timestamps when it writes. Even so, avoid re-running old windows casually, because it makes the store harder to reason about.
Reading online features
This example reads two drivers. One of them, 9999, was never materialized.
from feast import FeatureStore
store = FeatureStore(repo_path=".")
response = store.get_online_features(
features=[
"driver_hourly_stats:conv_rate",
"driver_hourly_stats:acc_rate",
],
entity_rows=[{"driver_id": 1001}, {"driver_id": 9999}],
)
result = response.to_dict()
print(result)The result is a dictionary of lists, one list per column, with one position per requested entity row:
{'driver_id': [1001, 9999],
'conv_rate': [0.62, None],
'acc_rate': [0.91, None]}Three points about this output:
- The values are plain Python numbers. Feature names appear without the view prefix unless you pass
full_feature_names=True. - A missing entity does not raise an error. It returns
None. Your serving code must decide what to do: use a default, use a fallback model, or fail the request. - The order of results matches the order of
entity_rows.
Staying inside the latency budget
Online reads are fast because the work per call is small. Latency still depends on several things you control:
- Network distance. A call to a remote Redis cluster costs a network round trip. Place the store near the service that reads it.
- Number of feature views. Each feature view you read from is a separate lookup against the store. Reading ten features from one view is cheaper than reading one feature from each of ten views.
- Number of entity rows. Batching several entities into one call is cheaper than looping with one call per entity.
- Client reuse. Create the
FeatureStoreobject once at process start. Building it per request re-reads the repository configuration and adds avoidable delay.
Measure on your own store before you tune. A simple timer around the call gives you the number that matters:
import time
from feast import FeatureStore
store = FeatureStore(repo_path=".")
start = time.perf_counter()
store.get_online_features(
features=["driver_hourly_stats:conv_rate"],
entity_rows=[{"driver_id": 1001}],
).to_dict()
elapsed_ms = (time.perf_counter() - start) * 1000
print(f"online read took {elapsed_ms:.1f} ms")The first call is often slower than later ones because connections and caches are cold. Time many calls and look at the 95th and 99th percentiles, not only the average.
Freshness and TTL
"Latest" means latest as of the last materialization or push, not latest in the real world. If materialization runs hourly, a value can be up to an hour old plus the age of the source row. The model sees a stale input and has no way to know.
The ttl on the feature view bounds how old a value can be before Feast treats it as expired. Depending on your Feast version, an expired value may come back as None instead of an old number. Check the behavior in your version with a small test, since this affects what your serving code must handle. A later chapter covers TTL and freshness in detail.
Common errors
- All values are
None. You calledget_online_featuresbefore materializing, or the materialization end timestamp was earlier than your data. Runfeast materialize-incrementalwith a current timestamp and retry. online=Falseon the view. The view is registered but never written to the online store.- Key mismatch. The entity row key must match the entity's join key name, here
driver_id, and its type. A string"1001"will not find an integer1001. - Registry out of date. If you changed a feature view but did not run
feast apply, the online store and the registry can disagree. - Using SQLite in production. It works until concurrent writers or multiple hosts appear, then it fails in confusing ways.
Exercise
Your service calls getonlinefeatures for driver 4242 and gets None for every feature, but gethistoricalfeatures returns data for that driver. Name two likely causes and how you would check each.
Show answer
First, materialization may never have run, or its end timestamp was earlier than the driver's rows, so nothing was copied into the online store. Check by running feast materialize-incremental with a current timestamp and calling getonlinefeatures again. Second, the feature view may have online=False, or the TTL may have expired the value. Check the feature view definition for online=True, and compare the driver's latest event_timestamp with the TTL window.