shuffleet
Home
Practice
Problems
Lessons
Plans
Compete
Challenges
Interviews
Leaderboard
Progress
Skills
Analytics
Submissions
Account
Settings

Late data and event time

Advanced · 4 min read

In two sentences

Every event has two times: when it happened (event time) and when your pipeline received it (processing time). A phone offline for an hour, a retry, a slow partner: events arrive late, and a daily total computed once, right after midnight, stays wrong forever unless the pipeline goes back and recomputes the days late events belong to.

See it

event_idevent_ts (happened)ingested_at (arrived)late by
104-01 10:0004-01 10:000
204-01 23:5804-02 00:4042 min
304-01 21:0004-03 09:0036 h
404-02 08:0004-02 08:000

The job computing 04-01 runs at 00:30 on 04-02. It sees 1 event for 04-01; the truth is 3. Events 2 and 3 belong to 04-01 but arrived after its run.

The next run (04-03 00:30) picks up everything that arrived since the last one: events 2 and 4. They touch two days, 04-01 and 04-02, so both are recomputed. Event 3 arrives after that run and will reopen 04-01 again the day after.

Events on two timelines, when they happened and when they arrived; the run for 04-01 misses the late ones

In SQL

Pick new rows by processing time (what arrived since the last run), recompute by event time (the days those rows belong to):

SQL
MERGE INTO daily_events t
USING (
  SELECT CAST(event_ts AS date) AS event_date, count(*) AS events
  FROM events
  WHERE CAST(event_ts AS date) IN (
    SELECT DISTINCT CAST(event_ts AS date)
    FROM events
    WHERE ingested_at > TIMESTAMP '2026-04-02 00:30'      -- the previous run
      AND ingested_at <= TIMESTAMP '2026-04-03 00:30'     -- this run
  )
  GROUP BY CAST(event_ts AS date)
) s
ON t.event_date = s.event_date
WHEN MATCHED THEN UPDATE SET events = s.events
WHEN NOT MATCHED THEN INSERT (event_date, events) VALUES (s.event_date, s.events);

Each touched day is recomputed from all its rows, not incremented, so re-running the job gives the same answer.

How late is your data? Measure it before choosing a strategy:

SQL
SELECT approx_percentile(date_diff('minute', event_ts, ingested_at), 0.99) AS p99_minutes_late
FROM events;

When to use it

The pipeline appends by arrival, finds the event days touched by new rows, and recomputes those partitions; events beyond the allowed lateness go to a corrections path

situationapproach
a few late events, cheap aggregatesrecompute every day touched by newly arrived rows (above)
lateness is bounded and known (p99 under 2 days)fixed lookback: recompute the last N days every run
streaming, state must stay boundedwatermark: accept events up to an allowed lateness, route later ones to a corrections table
finance, legal reportingclose periods: after a cut-off, late events become adjustments in the next period, never edits to the past

Best practices

  • Store both times on every row, and the batch or offset it came from. You can't reason about lateness you didn't record.
  • Partition raw data by arrival, aggregates by event time. Arrival makes "what's new" cheap; event time is what people report on.
  • Make the recompute idempotent: replace whole days (or MERGE full recomputed values), never add deltas.
  • Measure lateness and alert on it. A partner suddenly two days late is an incident, not a data quirk.
  • Tell readers which days are still open. A dashboard can mark the last N days as "may still change".

Common mistakes

  • Selecting new rows by event time. WHERE event_ts > last_run never picks up event 2: its event time is before the last run. Select by ingested_at.
  • Aggregating only the new rows and adding them. Adding 04-01's late events to yesterday's total works once; a re-run adds them twice.
  • A lookback shorter than real lateness. Recomputing 1 day back when partners are 3 days late keeps the totals wrong, quietly.
  • Using max(event_ts) as the cursor. One event from the future (a wrong device clock) moves the cursor past everything still to come.

What an interviewer asks next

  • "Your daily active users drop every day and recover the next morning. Why?" Late events: each day is computed before all its events arrive. Recompute touched days, or show recent days as provisional.
  • "How do watermarks bound state in streaming?" State for a window is kept until the watermark passes the window's end plus the allowed lateness, then dropped; later events go to a side output.

Go further

Akidau's Streaming 101 and 102 are the classic explanation of event time, processing time and watermarks; the ideas apply to batch as much as to streaming.

Practise it

Fix the Incremental Model That Loses Late Updates, then Incremental Daily Aggregates with Late Data and Compaction (hard), then Micro-Batch Deduplication with a Watermark (hard).