skip to content

Why does a Feast training set from `get_historical_features` show nulls for a nightly `spend_7d` feature, and how does the FeatureView's `ttl` cause it?

level: middleimportance: should knowfreq 12%

answer

  1. a look-back window per view
  2. measured from each entity row
  3. nightly value, afternoon impression
  4. default timedelta(days=0) means forever
  5. 0.66 apply fix for ttl updates

basics

~20 s

A FeatureView's ttl caps how far back from each entity row's timestamp the historical join looks; a nightly value older than ttl at that instant is dropped, leaving a null. Set ttl above the refresh interval plus load delay.

solid answer

~40 s

In `get_historical_features`, Feast joins each entity row to the latest feature value at or before the row's `event_timestamp`, but only within the view's `ttl`, measured back from that row's own timestamp. A `spend_7d` view written once a night with `ttl=timedelta(hours=12)` leaves every impression more than 12 hours after the last nightly row with a null, and players with no row on recent nights fall out too. The fix is a `ttl` covering the refresh cadence plus slack, such as two days for a daily feature. The default, `timedelta(days=0)`, means the features never expire, which removes the nulls at the cost of heavier joins and of letting arbitrarily old values through. In ordinary online reads `ttl` is not applied; in Feast 0.66 `feast apply` also stopped silently ignoring a `ttl` change to `None` or `timedelta(0)`.

go deeper

for a junior

Recall that ttl is a FeatureView argument, that it bounds how far back the historical join looks, and that the default of zero means no expiry.

for a middle

Explain how the window is measured from each entity row's timestamp, and size ttl from refresh interval, load delay and slack.

for a senior

Diagnose nulls by comparing row timestamps with source rows, check the registry rather than the file, and know the pre-0.66 apply bug.

for a principal

Weigh a strict ttl that exposes missing data against a loose one that hides staleness, and agree with model owners which they prefer.

## What `ttl` means on a Feast FeatureView A **FeatureView** groups features that come from one source and share an entity, such as a `player_spend` view keyed on `player_id` and fed by a nightly warehouse table. Its `ttl` argument is a `timedelta` that Feast's source describes as "the amount of time this group of features lives". In practice it is the **look-back window of the historical join**: - for each row of the entity dataframe, Feast considers only feature rows whose event timestamp is at or before that row's `event_timestamp`; - of those, it keeps only rows no older than `ttl` measured back from that same entity timestamp; - it returns the latest survivor, or a null when none survives. The docs stress that the window is relative to each entity row's timestamp, not to the moment the query runs. A training set covering last year therefore applies the same window to every row. ## Why a nightly feature goes null Take a `spend_7d` feature computed once a night, stamped 00:00, and an offer-impression log used as the entity dataframe. With `ttl=timedelta(hours=12)`: | Impression time | Latest `spend_7d` row | Age at impression | Joined? | |---|---|---|---| | 09:30 | 00:00 the same day | 9.5 h | yes | | 18:05 | 00:00 the same day | 18 h | no: null | | 10:00, player idle for 3 nights | 00:00 three days earlier | 58 h | no: null | Every afternoon and evening impression loses the feature, and so does any player whose nightly job emitted no row recently. Nothing fails: Feast returns nulls exactly as configured, and the model trains on a column that is missing whenever the timing is unlucky. The repair is to pick `ttl` from the feature's refresh contract: 1. Take the refresh interval (24 hours for a nightly job). 2. Add the worst load delay you expect (the job sometimes lands at 03:00). 3. Add slack for a missed run, if a one-day-old value is still acceptable to the model. 4. Set `ttl` to that sum, such as `timedelta(days=2)`, and re-run `feast apply`. Whether a value that old should be served at all is a product-agnostic freshness decision owned by the material on freshness bounds; `ttl` is where Feast records the answer for the offline join. ## The default and its cost `ttl` defaults to `timedelta(days=0)`, and Feast's own docstring says "a ttl of 0 indicates that this group of features lives forever". Leaving the default removes the window entirely: - **No nulls from age**, but a player idle for a year still gets last year's spend. - **Heavier queries**: the same docstring warns that large ttls or a ttl of 0 "can result in extremely computationally intensive queries", because the join has no lower bound. - **Incremental materialization's first run** also reads `ttl`: with no earlier run recorded, `materialize-incremental` starts at now minus `ttl`, and with a `ttl` of 0 it prints a notice and starts one year back. So 0 is not "drop everything"; it is the opposite. ## Offline window, not online expiry In the ordinary online read path `FeatureView.ttl` does not filter what `get_online_features` returns. The Redis online store's docs say so directly and point to its own `key_ttl_seconds`, a Redis key expiry applied per entity hash, for evicting old online data. A short `ttl` therefore makes training sets sparser without making served values fresher, which is one way the two paths quietly diverge. ## The Feast 0.66 apply fix Before Feast 0.66.0, `feast apply` silently ignored a change of `ttl` to `None` or to `timedelta(0)`: the registry kept the old window and the repository looked updated. 0.66.0 fixed that (changelog entry #6709). On an older release, check the registry after loosening a ttl to zero, for example with `feast registry-dump`, instead of trusting the Python file. ## Checklist when training rows come back null - Compare each null row's `event_timestamp` with the latest source row for that key. - Read the view's `ttl` from the registry, not only from the repository. - Check whether the source writes a row for idle entities at all. - Decide whether the fix is a longer `ttl` or a model that handles missing values on purpose.

  • Why not simply leave `ttl` at its default to get rid of the nulls?
    A `ttl` of 0 means the features never expire, so the join has no lower bound. Idle players get arbitrarily old spend values, and Feast's own docstring warns that large or zero ttls can make historical queries extremely expensive. It trades visible nulls for silently stale values and slower joins.
  • Does shortening `ttl` stop the online store from serving old values?
    Not in the ordinary read path. `FeatureView.ttl` bounds the offline join; online expiry is a store setting, such as the Redis store's `key_ttl_seconds`, which expires a whole entity hash at once.
  • You changed `ttl` to `timedelta(0)` and ran `feast apply` on Feast 0.65; joins still drop rows. Why?
    Before 0.66.0, `feast apply` silently ignored a ttl update to `None` or `timedelta(0)`, so the registry still held the old window. Upgrading to 0.66 fixes it; on the older release, confirm the stored value with `feast registry-dump`.

  • a ttl of 0 means every value expires immediately
  • ttl is measured back from the time the query runs
  • a short ttl keeps the online store fresh
  • nulls in a Feast training set always mean missing source data
  • the Python file proves what the registry holds

Assumes Feast 0.66; 0.66.0 fixed feast apply ignoring a ttl update to None or timedelta(0).