Sub topic 11
Late-Arriving and Corrected Data
Assume you understand features, labels, SQL joins, pandas, and basic timestamp handling. This chapter adds a second time axis to the point-in-time join: when the system learned about a fact.
Why event time is not enough
A feature row can describe an event that happened before prediction but arrived after prediction. Joining by event time alone would make that row available during training even though production could not have used it.
For example:
| event_ts | ingested_ts | prediction_ts | Should the row be used? |
|---|---|---|---|
| 2026-01-05 10:00 | 2026-01-05 10:05 | 2026-01-05 10:10 | Yes |
| 2026-01-05 10:00 | 2026-01-05 11:00 | 2026-01-05 10:10 | No |
| 2026-01-05 10:00 | 2026-01-06 09:00 | 2026-01-07 10:10 | Yes |
event_ts is when something happened in the world. ingested_ts is when the data system received or recorded it. prediction_ts is when the model would have made its prediction.
A point-in-time correct row must satisfy both conditions:
event_ts <= prediction_tsingested_ts <= prediction_ts
The first condition prevents future events from entering the past. The second prevents late-arriving information from entering a prediction that could not have seen it.
Corrected values and bitemporal history
A source system may later correct a value. For example, a transaction is first recorded as 20 dollars and later corrected to 200 dollars. If the correction arrives after the prediction, using 200 dollars in a historical training row creates leakage.
This is a bitemporal problem. Bitemporal data tracks two kinds of time:
- Valid time: when the fact applies in the real world, usually represented by
event_ts. - System time: when the database knew or stored that fact, represented by
ingested_ts.
Keep each version in an append-only history rather than overwriting the latest value. Then choose the newest version that was already known at prediction time.
WITH visible_rows AS (
SELECT
l.customer_id,
l.prediction_ts,
l.churned,
f.avg_spend_30d,
f.event_ts,
f.ingested_ts,
ROW_NUMBER() OVER (
PARTITION BY l.customer_id, l.prediction_ts
ORDER BY f.event_ts DESC, f.ingested_ts DESC
) AS rn
FROM labels AS l
LEFT JOIN feature_history AS f
ON f.customer_id = l.customer_id
AND f.event_ts <= l.prediction_ts
AND f.ingested_ts <= l.prediction_ts
)
SELECT
customer_id,
prediction_ts,
churned,
avg_spend_30d,
event_ts,
ingested_ts
FROM visible_rows
WHERE rn = 1;The ordering first selects the most recent event. If multiple versions describe that event, the later-ingested version wins, but only when it was already visible at prediction_ts.
A deliberate retrospective rebuild can use corrected data. That is a different dataset and must be labeled with a new feature-history version. Do not silently replace the original training data.
Practical safeguards
For each training row, store:
- The feature-history version.
- The query or transformation version.
- The selected
event_tsandingested_ts. - The prediction timestamp.
- The count of missing features caused by arrival delays.
Test both timestamp conditions explicitly:
joined = train.dropna(subset=["feature_ts", "ingested_ts"])
assert (joined["feature_ts"] <= joined["prediction_ts"]).all()
assert (joined["ingested_ts"] <= joined["prediction_ts"]).all()
assert not train.duplicated(
["customer_id", "prediction_ts"]
).any()A high missing-feature rate may indicate normal source delay, but it may also indicate that training and serving handle late data differently. Measure it by date and entity type, then compare it with production behavior.
Exercise
A feature event happened at 09:00, arrived at 10:30, and the prediction occurred at 10:00. Should the feature be included in the training row?
Show answer
No. Its event time is valid, but its ingestion time is after the prediction time, so the model could not have known it.