Batch and Stream Processing
Data keeps arriving: orders, clicks, sensor readings. The question is simple: do you process it in chunks later, or each event as it lands?
- Batch: collect events for a while (an hour, a day), then run one job over all of them.
- Stream: process every event within milliseconds to seconds of its arrival.
The difference is not speed of the engine. It’s how stale your answer is allowed to be.
Watch them side by side
Press Play. The same events go to both pipelines. Watch the counters and the “behind by” clock.
now
schedule
- The stream count tracks reality almost instantly. The batch count jumps on schedule and is always a little behind. Switch to micro-batch (the default mode of Spark Structured Streaming) and the gap shrinks.
Throughput and simplicity
Re-run a whole day if logic changes. Cheap, easy to test, easy to backfill. Results are minutes to hours old.
Freshness
Fraud alerts, live dashboards, recommendations. Needs state, checkpoints and care for late or duplicate events.
The middle ground
Tiny batches every second or so. Batch semantics with near-real-time latency.
The hard part of streaming: time
In batch, “yesterday’s data” is a closed folder. In a stream, an event from 10:59 can arrive at 11:03 (a phone was offline). So streaming engines separate:
- Event time: when it happened (in the payload).
- Processing time: when the engine saw it.
- Watermark: the engine’s guess that “no more events older than T will come”, which is when a window like 10:00–11:00 can be closed.
- Windows: tumbling (fixed, non-overlapping), sliding, and session windows.
Exactly-once results come from a replayable source + checkpointed state + idempotent or transactional sinks, not from the network delivering each message once.
How to choose
| Question | Lean batch | Lean stream |
|---|---|---|
| How fresh must the answer be? | Hours are fine | Seconds matter |
| Will logic change and need re-running on history? | Often | Rarely, or you keep a replayable log |
| Team experience with stateful systems | Low | High |
| Cost sensitivity | High | Freshness is worth paying for |
Most platforms do both: stream into Kafka for real-time use, and land the same events in a lakehouse table for batch analytics. See Lambda and Kappa.
Tools in 2026
- Batch: Apache Spark, dbt + a warehouse (Snowflake, BigQuery, ClickHouse), DuckDB for single-node jobs, Airflow / Dagster for scheduling.
- Stream: Apache Flink, Kafka Streams, Spark Structured Streaming, RisingWave / Materialize (streaming SQL).
- Logs / transport: Apache Kafka, Redpanda, Pulsar.
Learning Resources
Books
- Streaming Systems: Akidau, Chernyak, Lax
- Fundamentals of Data Engineering
- Designing Data-Intensive Applications: Martin Kleppmann
Articles
- Streaming 101 and Streaming 102: Tyler Akidau
- Apache Flink: Timely Stream Processing