Skip to content

Batch & stream processing · 1 of 3

Batch or stream?

Step 1 · The pattern

A nightly job for the sales report

Orders land in a log. Every night (here every 8 s) a batch job wakes, takes everything waiting and builds the sales report. The report is a night old by morning, and nobody minds. (Time is compressed; numbers are illustrative.)

  • an order
  • in the report

In short

Batch or stream?: how it works and how it breaks

Batch processing collects data and works through it on a schedule: every night, every hour. It is simple, cheap and easy to rerun, and its answers are as old as the gap between runs. Stream processing handles each event as it arrives, so answers are seconds old, at the cost of a service that runs all the time, keeps state, and must cope with failures, duplicates and late data. The choice follows from one question: how late can this answer be? A sales report read in the morning can be a night old. A fraud check that must stop an order before it ships cannot. Most systems need both: a stream path for the few decisions that cannot wait, and batch for heavy reports, rebuilds and anything that can.

What this simulation simplifies

  • A night between batch runs is 8 seconds here and shipping takes 3, so the gap and the deadline fit on screen; real gaps are hours.
  • The stream processor here never fails or falls behind; real ones restart, lag and see events out of order.

How this comes up in interviews

"When would you use batch processing, and when stream processing?"

Then they ask

  1. What does a stream processor have to handle that a batch job does not?
  2. How would you correct results after a bug in the streaming logic?
  3. Where do micro-batches fit?

A strong answer covers

  • The deciding question is how late the answer can be.
  • Batch: simple, cheap, easy to rerun; answers as old as the gap between runs.
  • Stream: answers in seconds; must handle state, restarts, late and duplicate events.
  • Use stream for decisions with short deadlines, batch for reports and rebuilds; many systems need both.
  • Keep events in a durable log so batch can recompute and the stream can be replayed.

Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.

On one page: the track cheat sheet.

Last updated: Official documentation

Diagrams are our own simulations: the timings, rates and counts in them are illustrative, not measurements. Captions are original wording.