Sub topic 16
Pushing fresh feature values from streams and events
This chapter assumes you have followed the earlier chapters. You should know how a FeatureView is defined, how feast materialize-incremental copies batch data into the online store, and how TTL limits which values are served. You should also be comfortable reading a small Python script that uses pandas.
Why materialization alone is not always enough
Materialization is a batch job. If it runs every hour, the online store is up to an hour behind the offline source. For features like avg_daily_trips that is fine. For signals that change within seconds, such as "number of failed payments in the last five minutes", an hourly copy makes the served value stale.
Push ingestion addresses this. Your own code, usually a stream processor or an event handler, writes new feature values straight into Feast. It does not wait for the next materialization run.
The pieces involved
A push-based setup adds one object to what you already have: a PushSource. It wraps a regular batch source, and a feature view reads from the push source.
- The push source has a name. You use that name when you push data.
- The batch source is the offline table behind the push source. Feast uses it for historical retrieval and for ordinary materialization.
- The feature view is unchanged except that its
sourceis the push source.
The same feature view can therefore be filled from two paths. Batch materialization backfills it. Pushes keep it current.
Defining a push source
Extend the feature repository from the earlier chapters. The batch source stays the same. Add a PushSource and point the feature view at it.
from datetime import timedelta
from feast import Entity, FeatureService, FeatureView, Field, FileSource, PushSource
from feast.types import Float32, Int64
driver = Entity(name="driver", join_keys=["driver_id"])
driver_stats_source = FileSource(
name="driver_hourly_stats_source",
path="data/driver_stats.parquet",
timestamp_field="event_timestamp",
created_timestamp_column="created",
)
driver_stats_push_source = PushSource(
name="driver_stats_push_source",
batch_source=driver_stats_source,
)
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_push_source,
)
driver_activity_v1 = FeatureService(
name="driver_activity_v1",
features=[driver_stats_fv[["conv_rate", "acc_rate"]]],
)Run feast apply again so the registry records the new source. Pushes to a source that is not in the registry fail.
Pushing a DataFrame
FeatureStore.push takes the push source name and a DataFrame. The DataFrame needs the entity key columns, every feature column in the schema, the event timestamp column, and the created timestamp column if the batch source defines one.
from datetime import datetime, timezone
import pandas as pd
from feast import FeatureStore
from feast.data_source import PushMode
store = FeatureStore(repo_path=".")
now = datetime.now(timezone.utc)
event_df = pd.DataFrame(
{
"driver_id": [1001],
"conv_rate": [0.91],
"acc_rate": [0.88],
"avg_daily_trips": [212],
"event_timestamp": [now],
"created": [now],
}
)
event_df = event_df.astype(
{"conv_rate": "float32", "acc_rate": "float32", "avg_daily_trips": "int64"}
)
store.push("driver_stats_push_source", event_df, to=PushMode.ONLINE)
print(
store.get_online_features(
features=["driver_hourly_stats:conv_rate", "driver_hourly_stats:acc_rate"],
entity_rows=[{"driver_id": 1001}],
).to_dict()
)The read at the end returns the pushed values immediately, without any materialization run.
Choosing where the push goes
The to argument controls the destination.
| Mode | Writes to | Typical use |
|---|---|---|
| `PushMode.ONLINE` | Online store only | Lowest latency. History is filled from another path. |
| `PushMode.OFFLINE` | Offline store only | Recording events for training without changing serving. |
| `PushMode.ONLINE_AND_OFFLINE` | Both | Keeps serving and training data consistent from one write. |
ONLINE_AND_OFFLINE depends on the offline store supporting writes. Check your offline store's documentation before relying on it.
Pushing over HTTP with the feature server
Not every producer is Python. The feature server exposes a push endpoint, so services in other languages can send events with plain HTTP. Start the server from the repository directory:
feast serve --port 6566Then send a request:
curl -X POST http://localhost:6566/push \
-H "Content-Type: application/json" \
-d '{
"push_source_name": "driver_stats_push_source",
"df": {
"driver_id": [1001],
"conv_rate": [0.93],
"acc_rate": [0.89],
"avg_daily_trips": [213],
"event_timestamp": ["2026-11-30T09:30:00"],
"created": ["2026-11-30T09:30:00"]
},
"to": "online"
}'The df field is a column-oriented object: each key is a column name and each value is a list of the same length.
Edge cases and failure modes
- Missing or mistyped columns. A missing feature column or a wrong dtype is a common cause of failed pushes. Cast types explicitly, as the example does for
Float32andInt64. - Out-of-order events. Streams can deliver late events. An old event pushed after a newer one may overwrite or be ignored depending on the online store. Test this with your store, and keep the event timestamp equal to when the event happened, not when you pushed it.
- TTL still applies. If you stop pushing for an entity, its value ages out of the TTL window. Online retrieval then returns nulls for it, as it does for materialized data.
- Throughput. Each push is a write to the online store. Pushing one row per event at high volume can overload it. Batch events into small DataFrames, for example a few hundred rows or one second of events, before pushing.
- Duplicates on retry. Pushing the same row twice with the same timestamps is harmless for the online store. In an append-only offline table it adds duplicate history, so retries need care when you write offline.
- Registry drift. After you rename a push source or change a schema, run
feast applybefore the producers restart.
When to use push and when to stay with batch
Use push when a feature must reflect events within seconds, and you already have a stream or event handler that computes it. Stay with scheduled materialization when hourly or daily freshness is acceptable, because it is simpler to operate and has fewer failure modes. Many production systems use both: batch for slow features and backfills, push for a small set of fast ones.
Exercise
Your fraud model reads failed_payments_5m from the online store. Values are pushed with PushMode.ONLINE, and the training set is built nightly with get_historical_features from the batch source, which is filled by a daily job. Name the problem this causes and give two ways to fix it.
Show answer
The online store holds fresh pushed values that are missing from the offline source, or arrive there only once a day. Training rows then see different values than serving did, which is training-serving skew. Fixes: (1) push with PushMode.ONLINE_AND_OFFLINE so both stores receive the same event, if the offline store supports writes; (2) write the same events to the batch source through the stream pipeline, and make sure the batch logic computes the feature the same way as the stream job.