Batch vs Stream Processing: How to Choose the Right Data Processing Model
Batch vs stream processing explained — latency, complexity, cost, windowing, late data, exactly-once semantics, Lambda and Kappa architectures, and how to decide.
Should your data pipeline run every night, or process each event the moment it happens? That's the batch versus streaming question. Streaming sounds more modern, but it comes with real complexity and cost. Many teams would be better served by batch jobs that run more often. Here's how to decide.
Key takeaways
- Batch processing handles bounded chunks of data on a schedule. It's simpler, cheaper and easier to reprocess.
- Stream processing handles unbounded data continuously, with latency from milliseconds to seconds.
- Choose streaming when freshness creates real value: fraud detection, real-time personalization, operational alerting.
- Streaming introduces hard problems: event time vs processing time, late data, state and exactly-once semantics.
- Micro-batching (running batches every few minutes) is often the pragmatic middle ground.
Batch processing
Batch jobs process a finite dataset: yesterday's orders, last hour's logs, a full table snapshot.
text[00:00 ─────────── 23:59 data] → nightly job → report ready at 02:00
Characteristics
- Latency: minutes to hours (or days).
- Throughput: very high; well suited to large historical computations.
- Simplicity: easy to reason about, test and debug. Re-run a job for a date if something went wrong.
- Cost-efficiency: compute runs only when needed.
Typical uses: BI reporting, financial reconciliation, ML model training, daily aggregates, data warehouse transformations (ETL vs ELT), backfills.
Stream processing
Streaming systems process events continuously as they arrive, often from Kafka or a similar event log (Apache Kafka explained).
textevent → process → update result → event → process → update result → ...
Characteristics
- Latency: milliseconds to seconds.
- Always-on infrastructure, which costs money even when traffic is low.
- Stateful operations (aggregations, joins, deduplication) require managed state that survives failures.
- Harder to test, debug and reprocess.
Typical uses: fraud and anomaly detection, real-time dashboards and alerting, live personalization and recommendations, IoT telemetry, updating search indexes and caches, CDC propagation (change data capture).
Comparison
| Batch | Streaming | |
|---|---|---|
| Data | Bounded | Unbounded |
| Latency | Minutes–days | Milliseconds–seconds |
| Complexity | Lower | Higher |
| Cost profile | Pay per run | Always-on |
| Reprocessing | Easy (re-run) | Harder (replay from log) |
| Handling late data | Natural (wait until complete) | Requires watermarks/windows |
| Best for | Reporting, training, reconciliation | Real-time decisions and reactions |
The hard parts of streaming
Event time vs processing time
An event's event time is when it happened; processing time is when your system sees it. A mobile app offline for an hour sends events that are an hour "late". If you aggregate by processing time, your "sales per minute" chart will be wrong.
Stream processors group by event time using windows:
- Tumbling windows: fixed, non-overlapping (every 5 minutes).
- Sliding/hopping windows: overlapping (10-minute windows every minute).
- Session windows: grouped by activity with gaps (a user's browsing session).
Late data and watermarks
How long do you wait for stragglers before emitting a window's result? A watermark is the system's estimate that "all events before time T have probably arrived". Events arriving after the watermark are late and can be dropped, sent to a side output, or used to update and correct earlier results. That's a trade-off between latency and completeness.
State management
Counting unique users per hour, joining a click stream with a user profile stream, or deduplicating events all require state. The stream processor must store it efficiently, checkpoint it for fault tolerance, and restore it after failures or deploys.
Exactly-once processing
Failures cause replays. Without care, a replayed event gets counted twice. Stream processors provide exactly-once guarantees for their internal state through checkpointing, but external side effects (writing to a database, calling an API) need idempotent writes or transactional sinks.
Architectures: Lambda and Kappa
Lambda architecture runs two paths: a batch layer for complete, accurate historical results and a speed layer for fresh approximate results, merged at query time. It's accurate and fresh, but you maintain the same logic twice.
Kappa architecture uses streaming only: everything is a stream, and reprocessing means replaying the log through a new version of the job. One codebase, but it requires long log retention and robust stream processing.
Today, many teams use a streaming ingestion + batch/micro-batch transformation approach: events and CDC land continuously in a lakehouse or warehouse, and SQL models refresh every few minutes or hours (data warehouse vs lake vs lakehouse).
Micro-batching: the pragmatic middle
If "real-time" really means "fresh within 5–15 minutes", you probably don't need a true streaming engine. Running incremental batch jobs frequently gives:
- Near-real-time freshness.
- Batch simplicity and tooling.
- Easy reprocessing.
Ask stakeholders: "What decision changes if this data is 10 seconds old versus 10 minutes old?" Often the answer is "none".
Decision guide
Choose streaming when:
- A decision or action must happen within seconds (block a fraudulent transaction, alert on an outage).
- The product experience depends on live data (live dashboards, collaborative apps, real-time recommendations).
- You need to propagate changes between systems continuously (CDC into search indexes or caches).
Choose batch or micro-batch when:
- Consumers are dashboards and reports reviewed hourly or daily.
- Computations need complete data (end-of-day financials).
- You're training ML models or running large historical analyses.
- The team is small, and operational simplicity matters.
Building reliable pipelines either way
- Idempotent writes: re-running a batch or replaying a stream must not duplicate results.
- Data quality checks: row counts, freshness, schema validation (data quality guide).
- Monitoring: job duration and failures for batch; consumer lag and throughput for streaming.
- Backfill strategy: how you'll recompute history when logic changes.
- Orchestration for batch dependencies (building data pipelines with Airflow).
FAQ
Is streaming always better than batch?
No. Streaming offers lower latency at the cost of complexity and always-on infrastructure. If your use case tolerates minutes or hours of delay, batch or micro-batch is usually cheaper and more reliable.
What is the difference between real-time and near-real-time?
Real-time typically means sub-second to a few seconds of latency; near-real-time usually means seconds to minutes. Many "real-time" business requirements are satisfied by near-real-time micro-batching.
Can the same code do both batch and streaming?
Some frameworks offer unified APIs where the same logic runs over bounded and unbounded data. This reduces duplication, but you still need to think about windows, late data and state for the streaming path.
What tools are used for stream processing?
Common choices include Apache Flink, Spark Structured Streaming, Kafka Streams and managed cloud streaming services. The right one depends on latency needs, state complexity, language and operational preferences.