Messaging & Stream Processing

Stream Processing

Computing continuously over an unbounded stream of events rather than a finite batch — aggregations, joins, and alerts that update as new events arrive, using windows to make "sum the last 5 minutes" a well-defined, finite question over an infinite stream.
  • Event time (when something actually happened) vs processing time (when the system saw it) diverge under network delay and retries — correctness usually needs event time
  • Windowing makes aggregation over an infinite stream tractable: tumbling (fixed, non-overlapping), sliding (overlapping), and session (gap-based) windows are the three common shapes
  • Watermarks are a stream processor's way of saying "I do not expect events older than time T anymore" — they bound how long a window waits for late data before closing
  • Stateful operators (a running count, a join across two streams) need their state checkpointed so a crash can resume rather than restart from zero
  • Not the same thing as Java's java.util.stream — that is a lazy, one-shot, in-process pipeline over data already fully available in memory; distributed stream processing (Flink, Kafka Streams, Spark Streaming) is a continuously running, fault-tolerant, unbounded computation
A windowed aggregation pipeline
Each window closes and emits once its watermark passes, not the instant the clock hits the boundary
Window types
WindowShapeExample use
TumblingFixed size, non-overlapping"Requests per minute", each event in exactly one window
SlidingFixed size, overlapping"Rolling 5-minute average", updated every 30 seconds
SessionGap-based, variable size"User activity session", closes after N minutes of inactivity
Sources
  • Designing Data-Intensive ApplicationsCh. 11 — Stream Processing
  • System Design: The Big Archive (2024 ed.)Data Architecture — Stream Processing