Check the same feature version, cutoff and arrival policy before interpreting equal or different values.
Problem
When you need this. The return model was trained on a particular event-count definition. A current feature reader can produce a different count if it includes late arrivals, uses another window or reads a snapshot that is too old. Comparing the two numbers alone does not tell you which of those rules changed.
This workshop takes the final original cutoff from the feature history that the previous step created. It then gets the value three ways, from the same inputs and policy: the current projection, a historical lookup and a direct recomputation.
Concepts
Training-serving parity means that training and prediction calculate the intended feature consistently. Before you compare two values, check that both use the same feature definition, entity, input snapshot, cutoff and arrival rule. If any of those differ, a different value may be expected rather than a bug.
The online projection stores one current value per feature and user. It answers a read for the present; it cannot answer an arbitrary historical query after a newer cutoff replaces the projection. Retained history supplies that earlier view.
Freshness is the age of the feature cutoff relative to the read time. A recent write of an old cutoff does not make the feature current. The reader checks availability first: a cutoff or publication time later than the read time is unavailable, even if its computed age is small or negative.
For this fixture, the three same-snapshot computations return one. Changing only the arrival rule admits the deliberately late event and returns two.
Architecture
Hold these fixed: user-00, cutoff 2026-01-14 12:00 UTC, one-day count, events and arrivals before that cutoff.
- Current projection
- 1
- Historical lookup
- 1
- Direct calculation
- 1
The same-snapshot comparison returns true. Changing the arrival rule produces 2.
Past the 60-minute age limit: stale; no value.
Unknown user: missing; no value.
Working code
Download the shared application and tests, unzip it and enter mlops-return-workflow/. Keep the same directory throughout the course. Create the environment once. This workshop uses the standard library.
python3.12 -m venv .venv
source .venv/bin/activateOn PowerShell, activate with .venv\Scripts\Activate.ps1.
Compare one eligible snapshot
Run the history command first. The parity command uses the final original cutoff from that history, so the one-row current projection and the retained historical row refer to the same feature snapshot.
def parity_report(source,database):
fixture=w.strict_json(source);store=ReturnHistory(database)
try:
# Use the final original cutoff, so the online projection and reference address the same snapshot.
cutoff=max(minute(o['predict_at']) for o in fixture['observations']);key='user_events_1d@v1';entity='user-00'
now=cutoff+30;online=store.read_online(key,entity,now,60)
original=store.point_in_time(key,entity,cutoff)
direct=compute(COUNT,source_rows(fixture['events']),cutoff,'as_known').get(entity,0)
corrected=compute(COUNT,source_rows(fixture['events']),cutoff,'corrected').get(entity,0)
return {'cutoff':cutoff,'value':online['value'],'same_snapshot_parity':online['value']==original['value']==direct,
'different_arrival_rule_value':corrected,'stale_status':store.read_online(key,entity,cutoff+61,60)['status'],
'unknown_user_status':store.read_online(key,'unknown-user',now,60)['status']}
finally:store.close()python adapt.py parity --work work/adaptations{
"cutoff": 19440,
"value": 1,
"same_snapshot_parity": true,
"different_arrival_rule_value": 2,
"stale_status": "stale",
"unknown_user_status": "missing"
}Read same_snapshot_parity next to different_arrival_rule_value. Then inspect stale_status and unknown_user_status. The store withholds a stale value and reports an unknown user as missing instead of converting either case into zero.
This output is from a saved local Python/SQLite run in recorded-adaptations/; it makes no remote API calls. Your commands write to work/. Read the actual command records. Use a fresh work directory for another attempt.
Failure cases
Run test_same_snapshot_parity_and_staleness and test_current_online_projection_cannot_answer_past_time. Together they check the stored value, the current read, the direct recomputation and the historical boundary.
When the values disagree, compare the cutoff and arrival rule of each read before you change the feature code.
Equal counts for one snapshot do not mean that every later feature read will agree. Keep the comparison on representative boundaries, including no activity, late arrivals, unavailable publications and the maximum allowed age.
python -m unittest -v test_workflow.py test_foundations.pyRunning and scaling the workshop
The current reader is a local function over SQLite. It does not expose a network endpoint. The 60-minute age limit is a policy declared for this exercise. It shows one accepted read and one refused read.
A larger deployment needs a measured freshness requirement and a fallback policy for missing or stale data. A fallback changes what the application does, so evaluate it as application behavior; do not add it inside a storage client.
Key takeaways
- Compare the same snapshot before diagnosing a calculation defect.
- Age starts at the feature cutoff, not the latest write.
- A current projection is not a substitute for historical feature storage.
Best practices
Return an explicit missing, stale or unavailable status alongside the value.
Test a deliberately different arrival rule so that the parity check can detect a real semantic change.
Send historical queries to retained history; use the online projection only for reads at the present time.
Check your understanding
Does writing yesterday’s feature again today satisfy a current-feature freshness requirement?
Show the explanation
No. The feature still summarizes yesterday’s cutoff. A new publication time does not make the underlying event window newer.
Read the explanation
The online projection represents its current state and refuses a request for an earlier incompatible time. Use historical storage to reconstruct that prediction.