Process data in big chunks later, or one event at a time as it arrives.
There are two ways to process data. Batch processing collects data for a while and processes it in one big job. Stream processing handles each event as soon as it arrives.
Data does not always arrive in neat files. Clicks, payments, sensor readings and logs flow in continuously. We can treat this data in two ways.
Batch processing works on a bounded set of data: all of yesterday's orders, for example. A job reads the whole set, computes the result and stops. It usually runs on a schedule (every hour, every night).
Stream processing works on an unbounded flow of events that never ends. A job runs all the time, updates its result with each event, and answers with low delay. Because the stream has no end, it usually computes over windows (for example, the last 5 minutes).
| Batch | Stream | |
|---|---|---|
| Input | A bounded set (a file, a table, a day of data) | An unbounded flow of events |
| When it runs | On a schedule or on demand, then stops | All the time |
| Latency | Minutes to hours | Milliseconds to seconds |
| Throughput | Very high, reads data in bulk | High, but limited by how fast events can be handled |
| Complexity | Simpler to write, test and rerun | Harder: ordering, state, late events, failures |
| Cost shape | Pay while jobs run | Pay for always-on capacity |
| Typical tools | Hadoop MapReduce, Spark batch, SQL on a warehouse | Kafka Streams, Apache Flink, Spark Structured Streaming |
| Idea | Meaning | Why it matters |
|---|---|---|
| Window | A slice of the stream to aggregate over (tumbling, sliding, session) | A stream never ends, so counts need a time frame. |
| Event time vs processing time | When it happened vs when we saw it | Events can arrive late or out of order. |
| Watermark | The system's estimate of how far event time has progressed | Decides when a window can be closed and its result emitted. |
| State | Data the job remembers between events (counts, sums) | Must survive crashes, so it is checkpointed. |
| Delivery guarantees | At most once, at least once, exactly once | Decides whether results can be lost or counted twice. |
| Backpressure | A slow job tells the source to slow down | Prevents overload and a growing backlog. |
A simplified model with no random numbers. A batch job starts when its window ends and takes 3 s plus 4 ms per event. The stream job answers in about 0.2 s and can handle 150 events per second. Real numbers depend on the system.
| Term | Meaning in easy words |
|---|---|
| Batch processing | Processing a bounded set of collected data in one job |
| Stream processing | Processing events continuously, as they arrive |
| Bounded / unbounded data | A data set with an end (bounded) or an endless flow of events (unbounded) |
| Latency | How long it takes from an event happening to a result being available |
| Throughput | How much data is processed per unit of time |
| Window | A slice of a stream (by time or count) used for an aggregate |
| Event time | The moment an event really happened |
| Processing time | The moment the system handles the event |
| Watermark | An estimate of how far event time has progressed, used to close windows |
| Checkpoint | A saved copy of a job's state, used to recover after a crash |
| Backpressure | A slow consumer signals the source to slow down |
| Choice | We gain | We lose |
|---|---|---|
| Batch every day | Simplicity and low cost | Answers up to a day old |
| Batch every few minutes (micro-batch) | Fresher answers, simple model | Many small jobs, each paying start-up cost |
| True stream | Lowest delay | Complexity, always-on cost |
| Exactly-once results | No lost or double counts | Extra coordination and some overhead |
| At-least-once results | Simpler and faster | Duplicates unless your logic handles them |
| Both (batch and stream) | Live view and exact history | Two pipelines to build and keep consistent |