Sub topic 16
Pushing Fresh Feature Values from Streams and Events
Assume you know Python, pandas DataFrames, basic machine learning, and the difference between batch data and real-time serving. This chapter focuses on Feast push sources, which let an application send new feature values into a feature store when events arrive.
Why push ingestion is useful
A batch pipeline might compute features every hour. That is sufficient for slowly changing values, but some models need information from the last few seconds. Examples include a driver's current activity, a user's recent transaction count, or the number of requests from an IP address.
With push ingestion, an event consumer or application computes a feature row and sends it to Feast. Feast can write the row to the online store immediately. A later call to get_online_features can then return the new value.
A push source does not automatically consume Kafka, Kinesis, or another message system. Your application still needs to read the event, validate it, compute the feature, and call the Feast SDK.
Define a push source
A PushSource connects incoming rows to a feature view. It usually has a batch source as well. The batch source provides historical data for training and backfills, while the push path provides fresh values for serving.
from datetime import timedelta
from feast import Entity, FeatureView, Field, FileSource, PushSource
from feast.types import Float32, Int64
driver = Entity(name="driver", join_keys=["driver_id"])
historical_source = FileSource(
name="driver_stats_history",
path="data/driver_stats.parquet",
timestamp_field="event_timestamp",
)
driver_push_source = PushSource(
name="driver_stats_push",
batch_source=historical_source,
)
driver_stats = 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_push_source,
)The pushed DataFrame must contain the entity join key, the feature columns, and an event timestamp. The timestamp describes when the observation happened, not merely when the application received it.
Push online, offline, or both
After registering the definitions with feast apply, application code can push a row.
from datetime import datetime, timezone
import pandas as pd
from feast import FeatureStore, PushMode
store = FeatureStore(repo_path=".")
updates = pd.DataFrame(
{
"driver_id": [1001],
"event_timestamp": [datetime.now(timezone.utc)],
"conv_rate": [0.82],
"acc_rate": [0.96],
"avg_daily_trips": [18],
}
)
store.push(
"driver_stats_push",
updates,
to=PushMode.ONLINE_AND_OFFLINE,
)PushMode.ONLINE updates only the low-latency store. PushMode.OFFLINE writes to the historical path when the configured setup supports it. ONLINE_AND_OFFLINE sends the value to both destinations. Choose the destination based on whether the event must be available for future training as well as current inference.
| Mode | Main use | Main risk |
|---|---|---|
| `ONLINE` | Immediate inference updates | The value may not become training history |
| `OFFLINE` | Historical accumulation or backfill | It does not provide immediate online serving |
| `ONLINE_AND_OFFLINE` | Keep serving and history aligned | Duplicate or out-of-order events need handling |
Event ordering and reliability
Streaming systems can deliver duplicates or delayed events. Use event timestamps consistently and make the producer retry safely. Validate entity keys and feature types before calling push. Monitor push failures and online-store write latency.
Exercise
A feature must be available for inference within seconds, but it also belongs in tomorrow's training set. Which push mode should you consider first, and what operational issue must you handle?
Show answer
Start with PushMode.ONLINEANDOFFLINE. Handle duplicate, delayed, or failed events with idempotent processing, event timestamps, retries, and monitoring.