Stream Processing Concepts

Understand events, event time vs processing time, windows, watermarks, state, delivery guarantees and when streaming is worth its cost.

Intermediate · about 4 hours · difficulty 3/5

Learn first: The Data Lifecycle and Pipeline Architecture, ETL vs ELT and Load Patterns

Streaming systems process unbounded data: events keep arriving forever. The concepts are different from batch and are a common source of interview questions.

Events and time

  • An event is an immutable fact: "payment 123 succeeded at 10:02:05".
  • Event time: when it happened. Processing time: when your system saw it. They differ because of network delays and offline devices (a delivery partner's phone losing signal in a basement).
  • Correct results use event time.

Windows

  • Tumbling: fixed, non-overlapping (orders per minute).
  • Sliding or hopping: overlapping (orders in the last 5 minutes, updated every minute).
  • Session: grouped by gaps in activity.

Watermarks and late data

A watermark says "I believe I have seen all events up to time T". It lets the engine close windows and drop or side-output data that arrives too late. Trade-off: waiting longer is more complete but slower.

State and guarantees

  • Aggregations and joins keep state; it must be checkpointed to survive failures.
  • Delivery semantics: at-most-once, at-least-once, exactly-once. Exactly-once end to end needs cooperation between the source, the engine and an idempotent or transactional sink.

When to stream

Fraud detection on UPI payments, live order tracking, real-time inventory and alerting justify streaming. Most reporting does not. Streaming costs more to build and operate. Micro-batch (every few minutes) is often a pragmatic middle ground.

Pitfalls

  • Using processing time and getting wrong numbers whenever events are delayed.
  • Assuming exactly-once because the engine advertises it while writing to a non-idempotent sink.

You are ready to move on when you can explain, with a food delivery example, how a 5-minute tumbling window with a 2-minute watermark handles an event that arrives 3 minutes late.

Key concepts

  • Events and immutability
  • Event time vs processing time
  • Tumbling, sliding, session windows
  • Watermarks and late data
  • Stateful processing and checkpoints
  • Delivery semantics
  • Micro-batch vs continuous
  • Lambda vs Kappa architecture

Mini project

Write a small Python simulation that generates delivery events with random delays, then compute 1-minute tumbling counts by processing time and by event time with a watermark. Plot or tabulate how the two results differ.

Check yourself

Why can a pipeline that is 'exactly-once' inside the engine still produce duplicates in the target database?

Free resources