Event-Time Tumbling Windows With Watermarks and Late Data

Last updated: November 29, 2026

Quick Overview

Process a stream of (event time, key, value) records that can arrive out of order, computing per-key sums over fixed tumbling windows, emitting each window once a watermark (max event time minus allowed lateness) passes its end, and counting events that arrive after their window was finalized.

Chalk
Coding & Algorithms
Software Engineer
Chalk
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Process a stream of (event time, key, value) records that can arrive out of order, computing per-key sums over fixed tumbling windows, emitting each window once a watermark (max event time minus allowed lateness) passes its end, and counting events that arrive after their window was finalized.

Chalk computes streaming features from Kafka and Kinesis sources, and the same window must produce the value served online and the value backfilled offline. This problem probes event time versus arrival time, deterministic finalization, and an honest policy for late data, all with efficient state.

What the Interviewer Expects
  • Assigns events to windows by event time with `ts - ts % size`
  • Tracks a monotonic watermark and finalizes windows only when it passes their end
  • Emits windows in start order using a min heap of open windows
  • Drops and counts events for already finalized windows rather than silently mutating emitted results
  • Bounds state: only open windows are retained
  • Provides a flush for end of stream
Key Topics to Cover
stream processing
watermarks
tumbling windows
heaps
late data
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you support late updates by emitting corrections (retractions) instead of dropping?
  • With many partitions, how is the global watermark computed, and what happens if one partition goes idle?
  • How would you change this for sliding (hopping) windows of 1 hour every 5 minutes?
  • How would you checkpoint this state so a restart does not double count?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Window size S, allowed lateness L. Windows are [k*S, (k+1)*S). process(ts, key, value) returns any windows that became final, as (start, key, sum). Watermark = max event time seen minus L....

High-Level Design

State: open[start][key] -> sum, a min heap of open window starts, max_ts, and closed_upto, the highest watermark ever applied. On each event: compute its window; if that window ended at or befor...


Submit Your Answer
Markdown supported

Related Questions