Feature freshness: prevent stale values at prediction time
In this article (3 sections)
A feature can have the right name, type and value range while being too old to support a decision. Freshness is measured relative to prediction time, not the wall clock when a monitoring query runs.
Enforce a boundary with explicit timestamps
Our teaching contract accepts feature age up to and including 24 hours. Four rows share decision hour 100:
| Row | Feature as-of | Age | Status |
|---|---|---|---|
| A | 99 | 1 | Fresh |
| B | 75 | 25 | Stale |
| C | 101 | -1 | Future |
| D | 76 | 24 | Fresh |
Row C is more serious than a stale value: its timestamp is after the decision, so historical training would leak future information. The counts reconcile to two fresh, one stale and one future.
from feature_cases import freshness_case
r = freshness_case()
assert r['maximum_age_hours'] == 24
assert r['counts'] == {'fresh': 2, 'stale': 1, 'future': 1}
assert next(row for row in r['rows'] if row['id'] == 'D')['status'] == 'fresh'
assert next(row for row in r['rows'] if row['id'] == 'C')['age_hours'] == -1
print(r)Run it in the feature-engineering lab. The inclusive 24-hour boundary is part of the contract and receives a direct test.
Design fallback by feature importance and action risk
When a feature is stale, options include rejecting the request, using a last-known value with an age indicator, switching to a reduced model or routing to manual review. The fallback must be evaluated on realistic stale patterns. Substituting zero silently changes semantics.
Record event time, feature as-of time, ingestion time and computation time. A pipeline can be recently refreshed from old source data. Monitor both source lag and materialization lag.
Freshness thresholds should match how quickly the underlying quantity changes and the cost of error. Account age can tolerate longer lag than a fraud velocity feature. Store the threshold in the feature dictionary and serving schema.
For training, reconstruct the value and freshness status that would have existed at each historical decision. Current snapshots can hide past outages and backfills.
Exercise: add per-feature age thresholds and a reduced-model fallback. Inject a two-hour source outage and compare availability, predictions and error on a held-out simulation. Log which path produced every score.
NeuraPath's Data Science course treats timestamps as model inputs and controls. Freshness failures are observable states with tested responses.
Continue learning
This article is part of the Feature engineering and data quality sequence. Use the neighbouring tasks when you need the prerequisite or the next application.
- Review the prerequisite or neighbouring task in Detect training-serving skew with schema contracts.
- Continue with Design a feature dictionary with owners and units.
Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.
This article is part of our Data Science programme — 6 months. From data foundations to machine learning, deep learning and deployment.
Explore Data Science