Sub topic 6
Data Sources and Event Timestamps
This chapter assumes you know Python, pandas DataFrames, basic machine learning terms, and the difference between batch data and real-time serving. You will use those ideas to describe where feature values come from and when those values were valid.
Why timestamps matter
A feature value has a meaning in time. For example, a driver's conversion rate may be calculated from trips completed before 12:00. A training row at 12:00 must not use a conversion rate calculated from trips completed at 13:00.
A data source tells Feast where feature records are stored. A source also identifies the column that records when each record was valid. Feast calls this the event timestamp.
An event timestamp answers:
- When did the event or measurement happen?
- At what point could this feature value have been known?
- Which value should a historical training query use?
An ingestion timestamp answers a different question: when did the system receive or write the record?
The event timestamp is the key timestamp for point-in-time-correct training data. If the training row represents a prediction at 10:02, Feast can use the 10:00 value but must reject values from later events.
Defining a file data source
This example uses a Parquet file. Parquet is a columnar file format that works well for analytical data.
from feast import FileSource
driver_stats_source = FileSource(
name="driver_hourly_stats_source",
path="data/driver_stats.parquet",
timestamp_field="event_timestamp",
created_timestamp_column="created",
)The timestamp_field must name a column in the source. Each row should contain an event timestamp for the feature data.
The optional created_timestamp_column records when the row was created or ingested. Feast can use it to choose between duplicate records that have the same entity key and event timestamp. It does not replace the event timestamp.
A source row might look like this:
| driver_id | event_timestamp | created | conv_rate |
|---|---|---|---|
| 1001 | 2025-01-01 12:00:00 | 2025-01-01 12:05:00 | 0.42 |
Here, the conversion rate describes the driver's state at 12:00. The record arrived at 12:05.
Common timestamp errors
Using ingestion time as event time
If a late record arrives at 15:00 but describes an event from 14:00, setting its event timestamp to 15:00 makes the feature appear newer than it was. Historical queries can then produce incorrect training data.
Omitting timestamps
Without event timestamps, Feast cannot determine which feature value was available for a historical entity row. Training data may contain future information, causing label leakage.
Mixing time zones
Store timestamps consistently, preferably in UTC. A naive timestamp without a time zone can be interpreted differently by different pipelines.
When a source contains late-arriving data, preserve both timestamps. Use event time for feature validity and created time for ingestion history and duplicate handling.
Exercise
A trip happened at 09:00, reached the feature pipeline at 09:07, and was written to storage at 09:10. Which timestamp should represent when the trip feature was valid?
Show answer
The event timestamp should be 09:00. The later times describe ingestion and storage, not when the trip happened.