Batch vs Streaming
Freshness is a spectrum, not a binary
Batch processing moves data on a schedule while streaming moves it continuously with low latency. Each has different SLAs, failure semantics and cost profiles.
What you will learn
- Decide batch vs streaming from business latency requirements
- Explain the failure-model differences between the two
- Recognize hybrid patterns and when they make sense
What is this?
Batch processing collects data over an interval (daily, hourly) and processes it all at once, often at a fixed time. Streaming processes events continuously as they arrive, usually within seconds. The choice is governed by two questions: how fresh must the data be, and how much complexity can you afford?
Why do you need it?
- Freshness drives decisions — a fraud alert at +24h is worthless, a sales report at +24h is fine.
- Batch is dramatically simpler: run a job, it's either done or failed, retry cleanly.
- Streaming gives you near-real-time dashboards, alerts and feature serving, but adds exactly-once headaches, backpressure and state.
- Most warehouses still land batch; streaming feeds it in micro-batches.
Mental model
Mail vs text messages
Batch vs streaming
Mail is collected, sorted and delivered on a schedule — cheap, simple, fine for non-urgent deliveries. Text messages arrive the moment they are sent — complex infrastructure under the hood, but needed when timeliness is the point.
How it works
- A batch job reads a bounded chunk (file, table partition or day's events) and processes it start to finish.
- Orchestration triggers the job on schedule; on failure it can retry or re-run the whole window.
- A streaming pipeline consumes an unbounded log of events from a broker like Kafka.
- Stream processing aggregates with windowing (tumbling, sliding, session) and keeps state for joins or counts.
- Delivery semantics (at-least-once, exactly-once) gate how much duplicate handling downstream must do.
Batch vs streaming data paths.
In production
- Nightly batch reconciles banking ledgers — correctness matters more than seconds.
- Streaming detects fraudulent card swipes in under 2 seconds using a windowed count model.
- A hybrid: streaming loads fresh events into the lake hourly micro-batches, then a nightly batch builds the final modeled tables.
Best practices
- Work from the latency SLA backward: if +15 minutes is fine, don't build streaming.
- In batch, always process idempotently so re-runs are safe.
- In streaming, choose delivery semantics explicitly and document duplication guarantees.
- Use event time (when it happened) rather than processing time (when you saw it) for windowing.
Common mistakes
- Building a streaming pipeline for a daily report — complexity with zero payback.
- Assuming stream events arrive ordered or exactly once — they don't by default.
- Forgetting late data arrives after windows close, causing silent underestimates.
- Wiring batch tools to a stream and silently dropping events on bursty days.
Common issues
Streaming dashboard numbers drift backwardLate-arriving events were reprocessed into closed windows
Configure watermark/late-data handling or accept 'final after N minutes of lag' semantics.
Nightly batch misses a day occasionallyJob runs at fixed time but source wasn't ready, and there is no retry
Add dependency sensors plus retries, and re-run windows when the source catches up.
Duplicates appear in the warehouse from the streamAt-least-once delivery replayed events after a crash
Dedupe downstream with a primary key + window (publish_minus_processing) or use exactly-once sinks.
Debugging tips
- For batch lag, check orchestration status and the last successful run timestamp first.
- For stream lag, inspect consumer group offsets vs the broker's end offset.
- If late events keep changing numbers, check whether the windowing uses event time and handles late/Kafka-sidewater marks.
- Compare counts 'in (source)' vs 'out (target)' to prove whether events are being dropped or duplicated.
Interview checkpoint
Quick quiz
A fraud alert must fire within 3 seconds of a transaction. Which approach fits?
Streaming always produces data exactly once, in order.