Why time is the hard part of streaming

watermark >= window_end + allowed_lateness

An unbounded stream has no answer until you impose a boundary, and the boundary you pick decides which late events count.

Every aggregate over a stream is a promise about time. A window closes when the system decides no more events for it will count, usually by comparing event timestamps with a watermark. Teams that skip writing down this promise discover it later, in a number that changed after it was reported. The operator is arithmetic; the hard part is deciding when the arithmetic is finished.

Start with event time, the timestamp written into the record when it happened, rather than processing time, the clock of the machine that reads it. Flink assigns each event to a window by its event time. A watermark, a marker that flows with the data, says how far event time has progressed, and when it passes a window's end the operator emits that window's result. Allowed lateness is an explicit interval after that point during which a late event can still update the result. Because windows follow event time, the same input yields the same windows on every run, whatever the network delay or restart timing.

The abstraction hides the watermark's guess. It asserts how late data can be, and a source that buffers offline events breaks that assertion. Take a mobile app that goes offline for several minutes: its clicks carry old timestamps and arrive after the watermark has closed their window. Under a drop policy they vanish silently, so the conversion rate falls and looks like a product problem. Under a correction policy the window reopens after someone has already read the dashboard. Set allowed lateness too small and you undercount without warning; set it too large and every open window holds state longer, delaying every answer. Retries add a second failure: a replayed task re-emits a window through a sink that is not idempotent, and the total counts it twice.

Choose the window from the question first. An alert on per-minute errors and a report on hourly trends need different sizes, so the size follows the question, not habit. Measure real lateness on production traffic before setting allowed lateness, and expect minutes when sources buffer offline events. Keep that number in configuration where people can read it. Expose a late-event count as a metric so an undercount becomes visible. Checkpoint operator state every few seconds so a restart resumes from a consistent point instead of rebuilding windows from wall-clock time. Key sink writes by window and key so a replay overwrites rather than adds. If you cannot state the lateness policy in one sentence, the design is unfinished.

orders of magnitude
window size
seconds to minutes

The span of event time one aggregate covers. Shorter windows answer sooner and hold less state, but react more to noise.

allowed lateness
minutes

How long after a window closes it still accepts late events. Each extra minute keeps that window's state alive.

checkpoint interval
seconds

How often operator state is written to durable storage. Frequent checkpoints shorten replay after a failure but add write cost.

open windows per key
one per window still open

The state a single key holds at any moment. Multiplied across keys, it sets the memory a job needs.

field note

The naive version grouped whatever arrived in the last minute by the worker's own wall clock. It looked like batch with a smaller batch, and on ordered input it produced the right answer. Nobody had to think about time, because the machine's clock stood in for it.

The wall appeared when events arrived late or out of order. The same input produced different windows on different runs, because arrival timing sorted events into different minutes. A retry after a failure emitted a second result for a period already reported, so downstream consumers counted that period twice.

Flink's model separates event time, the timestamp carried by the record, from processing time, the clock of the machine doing the work. Watermarks track how far event time has progressed, so the system knows when a window can close. Allowed lateness makes the remaining wait an explicit policy rather than an accident of timing. The lesson: time is the design problem, and the operator is trivial by comparison.