Sub topic 3
Offline features: large, historical, batch access
What this chapter assumes
You should know Python and pandas, the basic machine learning workflow (training data, features, labels, inference), and how to run commands in a terminal. You should also know the difference between batch data and real-time serving. Earlier chapters introduced the registry, the offline store, and the online store. This chapter looks closely at the offline side.
What "offline" means in Feast
Offline features are feature values read in bulk from historical data. The reader is usually a training job, a backfill, or a batch scoring job. Three properties define the offline path:
- Volume. A request can return millions or billions of rows.
- History. The store keeps many values per entity, each with its own timestamp. It does not keep only the latest value.
- Latency tolerance. A query that runs for seconds or minutes is acceptable, because nobody is waiting on a single prediction.
The offline store is the system that holds this data and runs the queries. Feast does not own the data. It reads from your warehouse, lake, or files through an offline store implementation. In the local setup from the topic plan, that implementation is the file-based store:
project: driver_project
registry: data/registry.db
provider: local
online_store:
type: sqlite
path: data/online_store.db
offline_store:
type: fileThe offline_store block selects the engine. The file type reads Parquet files with pandas, which works well for learning and small projects. Production setups usually use a warehouse such as BigQuery, Snowflake, or Redshift, or a Spark engine. You change the type and its connection settings. Your feature definitions stay the same.
What the offline data looks like
An offline source is a table of feature values with one row per entity per timestamp. For the driver example, data/driver_stats.parquet might contain this:
| driver_id | event_timestamp | created | conv_rate | acc_rate | avg_daily_trips |
|---|---|---|---|---|---|
| 1001 | 2025-01-01 10:00 | 2025-01-01 10:05 | 0.52 | 0.91 | 14 |
| 1001 | 2025-01-01 11:00 | 2025-01-01 11:05 | 0.55 | 0.90 | 15 |
| 1002 | 2025-01-01 10:00 | 2025-01-01 10:05 | 0.31 | 0.84 | 9 |
| 1002 | 2025-01-01 12:00 | 2025-01-01 12:04 | 0.35 | 0.85 | 10 |
Driver 1001 has two rows because its features changed over time. This history is the reason the offline store exists. A training example from 10:30 must see the 10:00 values, not the 11:00 values, so the table has to keep both.
Two timestamp columns appear in the source definition:
event_timestampis when the feature values were true in the real world.createdis when the row was written. Feast uses it only to break ties when two rows share the sameevent_timestampfor one entity. The row with the latercreatedvalue wins.
Declaring the offline source
A FileSource points a feature view at the offline data. The definitions below come from the feature repository:
from datetime import timedelta
from feast import Entity, FeatureService, FeatureView, Field, FileSource
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_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,
)
driver_activity_v1 = FeatureService(
name="driver_activity_v1",
features=[driver_stats_fv[["conv_rate", "acc_rate"]]],
)The source tells Feast where the rows are and which column holds the event time. The feature view tells Feast which columns are features and which entity they belong to. The join key driver_id is what links a feature row to an entity row at query time.
How an offline query works
You read offline features with get_historical_features. You pass an entity DataFrame and a list of features. The entity DataFrame holds the keys and timestamps you want features for, usually one row per labeled example.
from datetime import datetime
import pandas as pd
from feast import FeatureStore
store = FeatureStore(repo_path=".")
entity_df = pd.DataFrame(
{
"driver_id": [1001, 1002],
"event_timestamp": [datetime(2025, 1, 1, 12, 0), datetime(2025, 1, 1, 13, 0)],
}
)
training_df = store.get_historical_features(
entity_df=entity_df,
features=[
"driver_hourly_stats:conv_rate",
"driver_hourly_stats:acc_rate",
"driver_hourly_stats:avg_daily_trips",
],
).to_df()For each row in entity_df, Feast looks in the offline source for rows with the same driver_id. It keeps only rows whose event_timestamp is at or before the entity row's timestamp, and also within the TTL window. From those it picks the latest one. This is a point-in-time join, and a later chapter covers it in detail. Here, note that the offline store answers the question "what did we know about this driver at this moment?" for every row of your entity DataFrame in a single call.
The flow looks like this:
Working with the result
get_historical_features returns a retrieval job. It does not run the query when you call it. The query runs when you call a method that reads the result, such as to_df(). Other methods exist for other output shapes, such as to_arrow(). With a warehouse offline store, the job can also write results to a table on the warehouse side, so large training sets never pass through your Python process. That matters when the result does not fit in memory.
The output has one row per entity row. It contains the original columns from entity_df plus one column per requested feature. If no feature row qualifies for an entity row, the feature value is null. This happens when the entity has no earlier row, or when the latest earlier row is older than the TTL.
Edge cases and common errors
- Missing
event_timestampin the entity DataFrame. Feast needs this column to do the point-in-time join. Without it, the call fails. - Timestamp time zones. Mixing time-zone-aware and naive timestamps between the entity DataFrame and the source can produce errors or wrong joins. Pick one convention, preferably UTC, and use it everywhere.
- Unexpected nulls. A null feature usually means no source row falls within the TTL before the entity timestamp. Check the TTL and the source data before suspecting a bug in Feast.
- Duplicate rows. Two source rows with the same entity key and
event_timestampare resolved bycreated. If you have nocreatedcolumn, the result for those rows may not be deterministic. - Future-dated entity timestamps. An entity row dated after your newest source row gets the newest value, and this value may be old. Staleness is silent unless you check for it.
- File store scale. The file offline store loads data into memory with pandas. It is fine for tutorials and tests, but it will not scale to warehouse-sized history.
Why the offline store is separate from the online store
The offline store holds the full history and is optimized for scans and joins over many rows. The online store holds only the latest value per entity and is optimized for single-key lookups in milliseconds. Feast keeps them separate because no single system does both well. Materialization, covered in a later chapter, copies the latest values from the offline source into the online store.
Both paths use the same feature view definitions. That shared definition is how Feast reduces training-serving skew: the training set and the served features come from one declared schema, not from two hand-written pipelines.
Exercise
A source table has two rows for driver 1001: one at 10:00 with convrate 0.52 and one at 11:00 with convrate 0.55. The feature view TTL is 1 day. You call gethistoricalfeatures with an entity row for driver 1001 at 10:45. What conv_rate do you get, and what do you get for an entity row at 09:30?
Show answer
At 10:45 you get 0.52, because the 11:00 row is later than the entity timestamp and is excluded, and the 10:00 row is the latest one at or before 10:45 and within the TTL. At 09:30 you get null, because no source row exists at or before that time.
Exercise
A training set built with gethistoricalfeatures has many null values for avgdailytrips, although the source file has data for those drivers. Name two likely causes and how you would check each.
Show answer
First, the entity timestamps may be earlier than the first source row for those drivers, or more than the TTL after the latest earlier row. Check by comparing the entity timestamps with the source eventtimestamp values and with the feature view's ttl. Second, the entity DataFrame and the source may use different time zone conventions, or the join keys may not match in type or value. Check the timestamp dtypes and the driverid values on both sides.