Video in progress
What is the difference between batch processing and stream processing, and when do you need which?
Batch collects data and processes it all at once at a set time (for example, every night). Stream processes each event as it arrives. Where the result can wait hours, batch is simpler; if you need it in seconds, use stream.
📖 Answer
An example: a bank builds a report over all transactions at the end of the day — that's batch. Blocking a suspicious card payment that same second — that's stream.
| Batch | Stream | |
|---|---|---|
| Latency | minutes to hours | milliseconds to seconds |
| Data | a bounded set | an unbounded flow |
| On failure | you rerun the job | you have to think about state, offsets, duplicates |
| Tools | Spring Batch, SQL, Spark | Kafka Streams, Flink |
Batch's biggest win is its simplicity. If a job fails, you fix it and run it again. A stream system, on the other hand, runs all the time: late events, restoring state on restart, duplicates — you have to deal with all of it.
So I always pin down the "real time" requirement. Often when the business says "real time" they mean "within 5 minutes" — and a small batch that runs every 5 minutes gives you that easily.
Sign up to mark studied questions and save your progress.