Stream processing is the continuous computation of unbounded datasets. Unlike batch processing, which operates on a static snapshot, stream processing must handle data that arrives late, out-of-order, or over inconsistent network conditions.
To achieve correctness, we must distinguish between:
In distributed systems, the gap between these two is non-deterministic. We rely on Event Time for accurate business logic (e.g., "how many clicks happened between 2:00 and 2:05?").
A Watermark is a control signal that tells the system: "I am confident that no more events with a timestamp earlier than T will arrive."
As events flow through the system, the engine tracks the maximum observed event time (T_{max}). It emits a watermark at T_{watermark} = T_{max} - \text{slack}.
Windowing allows us to group unbounded streams into finite chunks for aggregation.
Tumbling windows partition the stream into discrete, equal-sized segments.
[12:00, 12:01] window. An event at 12:01:01 falls into the [12:01, 12:02] window.Sliding windows have a fixed length but "slide" by a specific interval (the slide).
Session windows do not have a fixed size. They are defined by a "gap" of inactivity.
Stream processors (like Apache Flink) must maintain State (e.g., the current sum in a window). To ensure "Exactly-Once" semantics, the system periodically takes Checkpoints—consistent snapshots of the distributed state. In the event of a failure, the system rolls back to the last checkpoint and replays the stream from the corresponding offset in the message broker (e.g., Kafka).