Stream vs Batch Processing
Sooner or later, most system design interviews turn into a question about derived data. You've stored the clicks, the orders, the location pings. Now someone wants a number computed from them: clicks per ad per minute, revenue per merchant per day, trending hashtags in the last hour, a fraud score for this card right now. How you produce that number is the stream-vs-batch decision.
The two approaches answer the same question ("given these events, what's the result?") with very different trade-offs in latency, cost, correctness and operational pain. Picking the wrong one is a common way to build something either too slow for the product or far more complex than it needed to be.
We'll build it up in order:
- What batch and stream processing actually are, and the one difference that drives everything else.
- Batch processing: how it works and why it's still the easiest way to be correct.
- Stream processing: event time, windows, watermarks, state, and exactly-once.
- The middle ground (micro-batching), and how to combine the two (Lambda and Kappa).
- How to choose in an interview.
Bounded vs Unbounded Data
The cleanest way to think about the split is not "slow vs fast" but bounded vs unbounded input.
- Batch processing runs a job over a bounded dataset: yesterday's clicks, last hour's log files, a full table snapshot. The input is complete before the job starts. The job reads all of it, computes, writes an output, and exits.
- Stream processing runs a job over an unbounded dataset: events that keep arriving forever. The job never finishes. It updates its results as each event (or small group of events) arrives.
Everything else follows from that. Because a batch job sees all of its input, it can sort it, join it with anything, scan it twice, and produce an exact answer. Because a stream job never sees "all" of the input, it has to decide when a result is ready, what to do with data that shows up late, and how to remember what it has already seen across crashes.
A useful way to put it to your interviewer: batch trades latency for simplicity; streaming trades simplicity for latency. Your job is to figure out how much latency the product can tolerate and pay only for what it needs.