Sub topic 2
Three clocks: event time, ingestion time, and prediction time
This chapter assumes you know basic supervised learning, SQL joins and window functions, and pandas DataFrames. You should also be comfortable with timestamps and time zones. The previous chapter showed how temporal leakage inflates offline metrics. This chapter defines the three timestamps you need to prevent it.
Why one timestamp is not enough
Most tables carry a single column called created_at or timestamp. Teams use it for every purpose: ordering rows, joining, and splitting data. That works until two things differ: when something happened, and when your system learned about it.
Consider a customer who makes a purchase at 23:50 on Monday. The payment processor sends a batch file at 04:00 on Tuesday. Your pipeline loads it at 06:15. Three moments describe the same fact, and each answers a different question:
- When did it happen in the world?
- When did our system first have it?
- When are we asking the model to decide?
A training set is point-in-time correct only if the answer to the third question is later than the answer to the second for every feature value used. The second clock is the one most pipelines never record.
The three clocks
Event time
Event time is the moment a fact became true in the real world. A purchase happened, a plan was cancelled, or a sensor reading was taken. The source system usually supplies it. You often write it as event_ts.
Event time is stable. A purchase at 23:50 stays at 23:50 forever, whenever you load it. Event time is what you use to order facts and to compute windows such as "spend in the 30 days before now".
Ingestion time
Ingestion time is the moment your system recorded the fact and made it available for queries. You write it as ingested_ts. Your pipeline assigns it, not the source.
Ingestion time is never earlier than event time, apart from clock skew between machines. The gap between them is the latency of the data. It can be milliseconds for a streaming source and days for a monthly partner file.
Ingestion time answers a question that event time cannot: "If I had run this query at 05:00 on Tuesday, would this row have existed?" For the purchase above, the answer is no. Its event time is Monday, but its ingestion time is Tuesday at 06:15.
Prediction time
Prediction time is the moment the model is asked for a prediction, or, in training data, the moment you pretend it was asked. You write it as prediction_ts. It is the reference point for the whole training row.
In production, prediction time is the clock of the request. In a historical training set, it is a column in your label table. For a churn model, it might be the first day of each month for each customer.
The rule for every feature value in a row is:
- Its event time must be at or before
prediction_ts. - Its ingestion time must also be at or before
prediction_ts.
Rule 1 stops you from using facts that had not happened yet. Rule 2 stops you from using facts that had happened but that your system could not have known.
A timeline of one fact
The diagram shows the purchase example on a single axis. Only a prediction made after the ingestion point could have used the purchase.
The Tuesday 05:00 request is the dangerous one for training data. If your historical table has only event_ts, a join at prediction_ts = Tue 05:00 will include the Monday purchase, because Monday is before Tuesday. The model trains on a feature that production could not have supplied at that time. The offline metric rises and the production metric does not.
What each clock does in a pipeline
| Clock | Column | Who assigns it | Used for |
|---|---|---|---|
| Event time | `event_ts` | Source system | Ordering facts, window boundaries, as-of lookups |
| Ingestion time | `ingested_ts` | Your pipeline | Deciding what was visible at a given moment |
| Prediction time | `prediction_ts` | Label table or request | The cutoff that both other clocks are compared to |
Notice that prediction time is not a property of a feature. It is a property of the training row. The same feature history is joined against many different prediction times.
Seeing the difference in code
The following example builds a small feature history in which one value arrives late. It then compares a join that uses only event time with a join that also respects ingestion time.
import pandas as pd
history = pd.DataFrame(
{
"customer_id": [1, 1, 1],
"event_ts": pd.to_datetime(
["2026-03-01 10:00", "2026-03-10 10:00", "2026-03-20 10:00"]
),
"ingested_ts": pd.to_datetime(
["2026-03-01 10:05", "2026-03-10 10:05", "2026-03-25 08:00"]
),
"avg_spend_30d": [40.0, 55.0, 90.0],
}
)
prediction_ts = pd.Timestamp("2026-03-22 00:00")
# Event time only: sees the row that was not yet ingested.
by_event = history[history["event_ts"] <= prediction_ts]
print("event time only:", by_event.sort_values("event_ts").iloc[-1]["avg_spend_30d"])
# Event time and ingestion time: sees only what the system knew.
visible = history[
(history["event_ts"] <= prediction_ts)
& (history["ingested_ts"] <= prediction_ts)
]
print("both clocks:", visible.sort_values("event_ts").iloc[-1]["avg_spend_30d"])The first line prints 90.0. The row has event time March 20, so it passes the event-time filter, but it was ingested on March 25. The second line prints 55.0, which is the value the system would have returned on March 22. The later chapters on the as-of join and on late data build this filter into the full join. Here, the point is that two filters give two different training rows from the same data.
Where the clocks come from
You rarely get all three clocks for free. Check each source.
- Event time may be missing, or it may be the time the source system wrote the row, not the time the fact happened. A database column called
updated_atoften records the last edit, not the original event. If a row is edited after the fact,updated_atmoves forward and hides the true event time. - Ingestion time is only reliable if your pipeline writes it at load time and never overwrites it. A backfill that reloads old data and stamps it with the reload time makes old facts look as if they arrived recently. That is safe but wasteful, because those rows are excluded from past training rows. The opposite mistake is worse: copying event time into
ingested_tsto make the column non-null. That tells every query the data was visible instantly. - Prediction time must come from the real decision moment. If the production model scores customers at 02:00 each night, using midnight as the training prediction time is wrong whenever data between midnight and 02:00 would have been visible in one setting and not the other.
Time zones and precision
All three clocks should be stored in UTC with the same precision. Mixed zones cause leakage that is hard to see. A feature stamped 2026-03-22 00:00 in a local zone five hours ahead of UTC is really 2026-03-21 19:00 UTC. Compared naively with a UTC prediction time, it looks five hours older than it is, or in the other direction five hours newer.
In pandas, parse with utc=True and keep columns timezone-aware:
import pandas as pd
raw = pd.Series(["2026-03-22 00:00", "2026-03-22 05:30"])
event_ts = pd.to_datetime(raw, utc=True)
print(event_ts.dt.tz)Also decide how to treat equality. The rule in this tutorial is "at or before", so a feature stamped exactly at prediction_ts is allowed. That is correct only if a value stamped at that instant was available to the request. For streaming features computed after the request arrives, you may need a strict "before". Pick one rule, write it down, and apply it everywhere.
Common mistakes
- Joining on event time alone. Late-arriving rows leak into earlier predictions, as the Python example showed.
- Treating
updated_atas event time. Edited rows appear to have happened later than they did, or corrections silently overwrite history. - Setting prediction time to the label time. For a churn label observed 30 days after the decision, the prediction time is the decision date, not the date the label became known. Using the label date lets all features from the next 30 days into the row.
- Using one global "now" for training. Every row needs its own
prediction_ts. A single run timestamp makes every row see the latest features. - Mixing time zones. Convert to UTC at the boundary and keep it that way.
A practical checklist
Before building a training set, answer these for every source table:
- Which column is the true event time, and who writes it?
- Is there an ingestion timestamp, and is it set once and never changed?
- What is the typical and worst-case delay between the two?
- Are rows ever corrected, and if so, are old versions kept?
- What clock does the production request use, and in which time zone?
The answers decide whether a simple as-of join is enough or whether you need the second filter on ingestion time.
Exercise
A customer's refund happens on 2026-05-02 09:00 UTC. A partner sends it in a file that your pipeline loads on 2026-05-04 03:00 UTC. A training row has predictionts = 2026-05-03 12:00 UTC and uses a feature "refunds30d". Should the refund count toward this row? Name the clock that decides it and the reason.
Show answer
No. The event time (May 2, 09:00) is before the prediction time, so a filter on event time alone would include it. The ingestion time (May 4, 03:00) is after the prediction time, so the system did not have the refund at May 3, 12:00. The ingestion clock decides it, and a production request at that moment could not have seen the refund.
Exercise
A table has one column, updated_at, which changes whenever a customer's address is edited. A teammate uses it as event time for an "address_region" feature. Describe the leakage this can cause.
Show answer
When an address is edited, updated_at moves to the edit time and the old value is lost or overwritten. A training row at an earlier prediction time may then see the new region as if it were current, or may find no valid row at all. The feature reflects information from after the prediction time. The fix is to keep an append-only history with the real event time and a separate ingestion time.