Stream Simulator
An event happened at 10:00 and arrived at 10:07. Which window does it belong to, and is it counted? Everything difficult about stream processing follows from that gap between when something happened and when you found out about it.
Clock labels here — 10:00, 10:07 — are positions on a teaching timeline, not durations anybody measured. Lag figures come from the stream model in this repository. Which of these behaviours a given broker or engine actually exhibits varies, and the labs say where.
Two clocks. Event time is when the thing happened, and it is what every business question is about. Processing time is when your system saw it, and it is what is easy to implement. A pipeline that windows on processing time is answering a question nobody asked — and it never fails, it just quietly attributes a purchase to the wrong hour.
The unavoidable trade sits in one decision: how long to wait for late data before you emit a result. Wait longer and results are more complete and less timely. Wait less and the opposite. There is no configuration that gives you both, and a system that appears to be giving you both is discarding something without telling you.
Windows
Unbounded data cannot be aggregated without a boundary. A window is that boundary, and choosing it is a modelling decision, not a configuration one.
Move one event's event time and its arrival time independently. The first decides which window it belongs to; the second decides whether it is still open when the event turns up.
| id | happened | arrived | counted |
|---|---|---|---|
| a | 10:01 | 10:01 | yes |
| b | 10:02 | 10:02 | yes |
| c | 10:04 | 10:04 | yes |
| d | 10:06 | 10:06 | yes |
| e | 10:08 | 10:08 | yes |
| late | 10:00 | 10:07 | dropped |
- —Tumbling — fixed, non-overlapping. Every event lands in exactly one window, which is what makes the results additive across windows.
- —Sliding — fixed length, advancing by less than its length. Every event lands in several windows, so the results are not additive and summing them double-counts.
- —Session — bounded by a gap in activity rather than by the clock. The gap is a modelling parameter that changes every rate computed over it, and no source system emits one.