Incremental Daily Rollup That Publishes Days After a Lateness Watermark
Last updated: November 29, 2026
Quick Overview
Design and implement in Python a streaming daily rollup of event counts per key that publishes a day only after a watermark (latest event time minus allowed lateness) passes the day's end. Events for an already-published day must go to a corrections log rather than silently changing published numbers.
Meta
November 29, 20260
0
0 solved
Design and implement in Python a streaming daily rollup of event counts per key that publishes a day only after a watermark (latest event time minus allowed lateness) passes the day's end. Events for an already-published day must go to a corrections log rather than silently changing published numbers.
A data engineering onsite question at Meta, modeled on how daily metrics from mobile clients (which often upload events hours late) are finalized. The interviewer checks watermark reasoning, the trade-off between freshness and completeness, and how corrections flow downstream.
What the Interviewer Expects
- Bucket events by event time, not arrival time
- Track a watermark from the max event time minus lateness
- Publish days in order once fully behind the watermark
- Route late events for published days to corrections
- Explain the freshness versus completeness trade-off
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- What happens if one device has a badly wrong clock far in the future?
- How would you choose the lateness value from data?
- How would downstream dashboards consume corrections?
- How does this map to a batch system with daily partitions and a landing delay?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
Events are (event_ts_seconds, key) in arrival order, with event time possibly hours behind. Days are UTC (event_ts // 86400). Allowed lateness defaults to 2 hours. Published day numbers must be st...
Approach
Keep open days as nested counters. On each event, add it to its day if that day is open, else append a correction. Update the max event time; the watermark is max minus lateness. Then publish any open...