Why must training features be joined “as of” each label’s timestamp, and how does a point-in-time join work? Using a small user timeline, why do naive joins inflate offline metrics and then fail online, and what is one serving-time alternative?

ML system design, Data and features
Level L3 Intermediate. Length Medium. Nature Th+Mat Both.

What's being asked

Whether you understand temporal data leakage in production feature pipelines, can trace an as-of join accurately, and know practical ways to eliminate it.

Key idea

At serving time, a model only sees feature values recorded at or before the prediction moment tlabel. A point-in-time ('as of') join therefore matches each label row to the latest feature snapshot satisfying tfeat≤tlabel (within an optional TTL, or time-to-live, window), preventing future events or the label itself from leaking into training.

Steps

  1. Set up a worked timeline for user u1 with feature `orders_30d` (orders in the last 30 days): feature snapshots are recorded on `1 May 09:00` (`1`), `10 May 09:00` (`3`), `16 May 09:00` (`4`, updated after the purchase that follows Row B's visit) and `25 May 09:00` (`7`, the latest warehouse snapshot). Two label rows ask whether a visit ended in a purchase: Row A at `5 May 14:00` (y=0) and Row B at `15 May 18:00` (y=1).
  2. Apply the point-in-time as-of rule (tfeat≤tlabel): for Row A (`5 May 14:00`), the newest snapshot at or before that time is `1 May 09:00`, giving `orders_30d = 1`. For Row B (`15 May 18:00`), the newest snapshot at or before that time is `10 May 09:00`, giving `orders_30d = 3`.
  3. Contrast with naive joins: a naive join on the current latest snapshot (`25 May 09:00`) assigns `orders_30d = 7` to both Row A and Row B, leaking future orders. Even joining the `16 May 09:00` snapshot (`orders_30d = 4`) onto Row B leaks the very 15 May purchase that Row B is trying to predict.
  4. Explain the offline-to-online collapse: future feature values correlate strongly with later outcomes (or encode the outcome itself), so the model learns a false shortcut that inflates offline AUC (area under the receiver operating characteristic curve). In production, future values do not exist when the request arrives, so live accuracy collapses.
  5. Mention logging features at serving time as a clean alternative: whenever the online service scores a request, log the exact feature vector sent to the model alongside a request ID, then join the delayed label later. This avoids reconstructing historical aggregates altogether.

Common mistakes

How long your answer should be

Walk through the four-snapshot timeline, compare as-of vs leaked values, explain the offline/online gap, and note serving-time logging; about 3–4 minutes.

Read this

Previous in ML system design: What do p50 and p99 latency mean? Suppose a request fans out to 50 shards in parallel and waits for all of them, and each shard is slow (>100 ms) independently on 1% of calls. What fraction of requests is slow, how would you split a 200 ms p99 latency budget across ML serving stages, and how can you reduce tail latency?
Next in ML system design: Why do large recommenders and search engines split prediction into candidate generation (retrieval) followed by ranking? Suppose a catalogue has 10 million items and a heavy ranking model takes 50 µs per item; how does scoring the whole catalogue compare with using a two-tower model and approximate nearest neighbour (ANN) search to retrieve 1,000 candidates first?