With Feast, how do `get_historical_features` and `get_online_features` differ in what you pass, which store each reads, and which value each row receives?
answer
- two calls, two stores
- entity dataframe carries timestamps
- entity rows carry only keys
- as-of value bounded by ttl
- online store filled by materialize or push
basics
~20 sget_historical_features takes entity rows with timestamps, reads the offline store and returns each row's latest value at or before its timestamp within ttl; get_online_features takes keys only and returns the latest value loaded into the online store.
solid answer
~40 s`get_historical_features(entity_df=..., features=...)` is the training and batch-scoring call: the entity dataframe holds join keys plus an `event_timestamp` per row, Feast runs a point-in-time join against the feature views' batch sources in the offline store, and each row gets the latest feature value observed at or before its own timestamp, looking back no further than the view's `ttl`. It returns a lazy `RetrievalJob` you turn into data with `.to_df()` or `.to_arrow()`. `get_online_features(features=..., entity_rows=...)` is the serving call: rows carry keys only, Feast reads the online store, and you get whatever latest value `feast materialize`, `materialize-incremental` or a push has written there, as an `OnlineResponse`. Pass the same `FeatureService` to both so training and serving ask for the same features.
code
python · 23 linesfrom datetime import datetime, timezone
import pandas as pd
from feast import FeatureStore
store = FeatureStore(repo_path=".")
service = store.get_feature_service("offer_propensity_v1")
# Training: one row per player and the instant the offer was shown
entity_df = pd.DataFrame({
"player_id": [1001, 1002],
"event_timestamp": [
datetime(2026, 9, 14, 18, 5, tzinfo=timezone.utc),
datetime(2026, 9, 15, 9, 40, tzinfo=timezone.utc),
],
})
training_df = store.get_historical_features(
entity_df=entity_df, features=service
).to_df()
# Serving: keys only, latest value in the online store
online = store.get_online_features(
features=service, entity_rows=[{"player_id": 1001}]
).to_dict()go deeper
Recall the two calls, what each takes as entities, which store each reads, and that online values exist only after a materialize or a push.
Explain the point-in-time rule per entity row, how ttl bounds the look-back from each row's timestamp, and why one FeatureService should feed both calls.
Show how you would spot a training set built with now-timestamps, handle NOT_FOUND statuses at serving time, and log served features for later comparison.
Weigh where the entity dataframe is built, as a dataframe or warehouse SQL, and what a shared FeatureService per model version buys a platform with many consumers.
## Two calls for two jobs Feast keeps feature definitions in one registry but answers two very different questions, and it has one retrieval call for each: - **`get_historical_features`** answers "what did this entity's features look like at each of these past moments?" It builds **training sets** and runs **batch scoring**. - **`get_online_features`** answers "what are this entity's features right now?" It serves a model that scores a live request. Both calls accept the features to fetch either as a list of **feature references** (`"player_spend:spend_7d"`, the `<feature_view>:<feature>` form) or as a **`FeatureService`**, the object that groups the features one model version reads. Feast's docs recommend references only while experimenting and a feature service once a model is trained or served, because the same service passed to both calls guarantees both paths request the same columns. ## What you pass in | | `get_historical_features` | `get_online_features` | |---|---|---| | Entities | `entity_df`: a pandas dataframe or a SQL string | `entity_rows`: a list of key dicts, such as `[{"player_id": 1001}]` | | Timestamps | required, one `event_timestamp` per row | none; one value per key is wanted | | Store read | the offline store, through each view's batch source | the online store, such as Redis or SQLite | | Returns | a lazy `RetrievalJob` (`.to_df()`, `.to_arrow()`) | an `OnlineResponse` (`.to_dict()`, `.to_df()`) | | Typical caller | a training pipeline, a nightly scoring job | a request handler, or the feature server's `/get-online-features` | The entity dataframe's `event_timestamp` is the **upper bound** for each row. In Feast 0.66 the docs also describe an entity-less form that takes `start_date` and `end_date` instead, supported only on some offline stores, and it cannot be mixed with `entity_df` in the same call. ## What value each row gets On the historical path Feast performs a **point-in-time join** for each entity row: 1. It finds feature rows for that entity key in the view's batch source. 2. It keeps only rows whose event timestamp is at or before the entity row's `event_timestamp`. 3. It scans back no further than the feature view's `ttl`, measured from that entity row's timestamp, not from the time you run the query. 4. It returns the latest surviving value, or a null when nothing survives. A `ttl` of 0, the default, means the features never expire, so the scan has no lower bound. Why an as-of join is needed at all is a design question for the material on point-in-time joins; here the point is that Feast does it for you when you supply timestamps. On the online path there is no time travel. The online store holds the latest value per entity key and feature view, and `get_online_features` returns it. Two consequences matter in practice: - **Nothing is there until something writes it.** A batch-sourced feature view has no online values until `feast materialize`, `feast materialize-incremental` or a push loads them; a key that was never loaded comes back with a null value and a `NOT_FOUND` status rather than an error. - **The online path does not re-check history.** In the ordinary read path `FeatureView.ttl` does not filter online reads; the Redis store's docs say so explicitly and point to its `key_ttl_seconds` setting for online expiry. ## A worked example For an in-app-offer propensity model, a `player` entity with join key `player_id` and a feature service `offer_propensity_v1` grouping 7-day spend and session features: - the training job builds `entity_df` from the offer-impression log, one row per player and the instant the offer was shown, and calls `get_historical_features` so each impression gets the spend value the game could have known then; - the game backend, at request time, sends `{"player_id": 1001}` to `get_online_features` or to the feature server's `/get-online-features` endpoint (port 6566 by default with `feast serve`) and gets the latest materialized values. ## Common mistakes - Calling `get_historical_features` with every timestamp set to now and calling it a training set: that is the batch-scoring pattern, and it labels past outcomes with present features. - Expecting `get_online_features` to fall back to the offline store when a key is missing; it does not. - Treating `get_historical_features` as eager: nothing runs until you convert the `RetrievalJob`. - Assuming a feature service deploys a service; applying one only records a named group of features in the registry.
- What do you get from `get_online_features` for a player whose features were never materialized or pushed?No error. The response carries a null value for each requested feature of that key, with a `NOT_FOUND` status beside it. The online store is not backed by the offline store at read time, so a missing load shows up as nulls the model must handle, which is why the serving path should check statuses or default values deliberately.
- How do you capture what the online path actually served, so it can later be compared with training data?Give the `FeatureService` a `logging_config`, a `LoggingConfig` with an offline-store logging destination and a `sample_rate` (1.0 by default). Logged rows are written to the offline store through `write_logged_features`, keyed by the feature service, and can then be read back and compared with the historical values for the same keys.
- When would you pass a SQL string as `entity_df` instead of a dataframe?When the entity rows already live in the warehouse, such as every impression in a date range. Feast accepts a SQL query that returns the join keys and `event_timestamp`, so the join runs in the offline store without pulling the entity list into the client first.
- get_online_features reads the offline store when a key is missing
- get_historical_features returns today's values for every entity row
- the entity dataframe does not need timestamps for training data
- applying a FeatureService deploys an HTTP service
- online values appear as soon as feast apply registers a feature view