Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
Streaming vs batch: is being fast worth the cost?
Streaming's real engineering tax isn't "processing faster" — it's handling data that arrives late, out of order, or twice, in real time, instead of getting to assume it's already clean by the time you touch it.
The one distinction that decides everything
Batch processing collects data over a window and processes all of it at once, on a schedule — hourly, nightly. Streaming processes each event as it arrives, continuously, with results available near-instantly. The distinction isn't about data volume — it's about whether the VALUE of an insight decays before the next scheduled batch run would deliver it.
If a result being hours stale is fine, batch is simpler and cheaper. If the value of the insight decays within seconds — fraud, alerting, live UX — you need streaming.
Head to head
| Dimension | Streaming | Batch |
|---|---|---|
| Latency | Sub-second to seconds | Minutes to hours/days — as fresh as the last run |
| Complexity | Higher — disorder, windowing, exactly-once semantics | Lower — deterministic, easy to reprocess/backfill |
| Cost model | Needs always-on infrastructure | Can use cheap scheduled/spot compute |
| Failure recovery | Checkpointing / replay from an offset | Rerun the job — naturally idempotent |
| Use case shape | Fraud detection, live dashboards, alerting | End-of-day reports, ETL, large aggregate analytics |
| Tooling | Kafka Streams, Flink, Spark Structured Streaming | Spark, Airflow, dbt |
When to use each
Reach for batch
- Freshness of hours or days is genuinely fine
- Want simplicity and easy reprocessing/backfills
- Cost-sensitive — spot/scheduled compute is enough
- Complex joins/aggregations over huge historical windows
Reach for streaming
- Need sub-second to seconds decisions
- The insight’s value decays fast with delay
- Live UX — dashboards, alerts, personalization
- Fraud or anomaly detection at the moment it happens
Lambda and Kappa: running both
Many real systems run both paths deliberately: a fast streaming path gives approximate, real-time results immediately, while a slower batch path recomputes exact, corrected results later and reconciles the two (this is the Lambda architecture). Increasingly, teams instead push everything through the streaming engine and treat "batch" as simply a stream replayed over a bounded window (the Kappa architecture), to avoid maintaining two separate codepaths for the same logic.
Kappa (one streaming codepath, batch = replay a window) is gaining ground over Lambda's two-codepath approach specifically because maintaining the same logic twice, in two different processing models, is its own ongoing cost.
The real cost isn’t speed — it’s correctness under disorder
It's intuitive to think streaming is just "batch, but faster" — but the actual engineering tax streaming adds comes from a different place: events in the real world arrive out of order, late, or duplicated, because they cross an unreliable network from many independent sources. A completed batch window sidesteps this almost entirely — by the time you process it, the data for that window is already complete and effectively ordered, because you waited for the window to close before touching it.
Streaming has no such luxury: it has to make a decision on data as it arrives, without knowing whether more (older) data is still in flight. This forces explicit concepts batch gets for free — EVENT TIME vs PROCESSING TIME (when something actually happened vs when your system saw it), WATERMARKS (a heuristic for "how late are we willing to wait before assuming no more data is coming for this window"), and delivery semantics (exactly-once vs at-least-once, since a network retry can duplicate an event). None of this is about raw processing speed; it's the cost of making correct decisions on data whose completeness you can't yet verify.
Batch gets ordering and completeness for free by waiting. Streaming gives up that wait — and has to explicitly engineer around the disorder waiting would have quietly resolved.
A worked scenario: churn scoring vs live fraud detection
An e-commerce platform computes "customers likely to churn" scores in a nightly batch job over the full order history — being a day stale is completely fine here, and the job benefits from large historical joins that are much simpler to reason about once the day's data is known to be complete and ordered.
The same platform needs streaming for fraud detection on live checkout attempts, where a decision has to be made in the roughly 200ms before a payment authorizes — batch's next scheduled run, even an hour away, would be far too late to stop a fraudulent charge that's happening right now. Notice these aren't different scales of the same problem; they're genuinely different problems, one where waiting costs nothing and one where waiting is the failure.
Ask: what happens if this result arrives an hour late instead of instantly? If the answer is "nothing bad," batch is simpler and cheaper. If the answer is "the decision is now useless," you need streaming.
The flip point: the freshness where the cost crosses over
Latency aside, there is a cost crossover too. Streaming runs always-on; batch pays per run but has to run often to stay fresh. Say a batch run costs C_b and a streaming pipeline costs C_s per hour. To hit a freshness of F hours, batch runs 24/F times a day at (24/F)·C_b, while streaming costs 24·C_s. Setting them equal, the crossover is at F = C_b / C_s hours.
If a batch run costs $2 and streaming costs $0.50/hour, the crossover is F = 2 / 0.5 = 4 hours — streaming at $12/day versus batch at (24/4)·$2 = $12/day. So if you need data fresher than every ~4 hours, streaming is not just faster, it is cheaper — running batch that often costs more than just keeping the stream on. Tolerate staler than 4 hours and batch wins on cost. Plug in your own per-run and hourly figures; the crossover is simply their ratio.
The picture: event-time windows and a late event
@ label is when it arrived (processing time). e4 is out of order but still on time. When it arrived at 7.0 the watermark was only 4, so window [0,5) was still open. e7 arrived at 12.0, when the watermark was 9. Its window had fired at 9.3, so the stream drops it or routes it to a side output. A batch job that waits for all eight events counts it. Same data, two answers for the first window.Worked example: eight events, one watermark
Count events in 5-second tumbling windows by event time. The rule: watermark = the largest event time seen so far − 2 s, and a window fires once the watermark reaches its end. The events arrive in this order. The numbers are illustrative; the rule is the one Flink and Beam style engines apply.
| Arrives at | Event | Event time | Window | Max seen | Watermark | What happens |
|---|---|---|---|---|---|---|
| 1.2 | e1 | 1 | [0,5) | 1 | −1 | Counted |
| 3.5 | e2 | 3 | [0,5) | 3 | 1 | Counted |
| 6.1 | e3 | 6 | [5,10) | 6 | 4 | Counted |
| 7.0 | e4 | 4 | [0,5) | 6 | 4 | Out of order, but [0,5) is still open (4 < 5): counted |
| 9.3 | e5 | 9 | [5,10) | 9 | 7 | Counted. 7 ≥ 5, so [0,5) fires: 3 |
| 11.4 | e6 | 11 | [10,15) | 11 | 9 | Counted |
| 12.0 | e7 | 2 | [0,5) | 11 | 9 | Late. [0,5) already fired: dropped or sent to a side output |
| 13.2 | e8 | 13 | [10,15) | 13 | 11 | Counted. 11 ≥ 10, so [5,10) fires: 2 |
| end | — | — | — | — | +∞ | Input ends, so [10,15) fires: 2 |
The stream reports 3, 2, 2. A batch job run after everything has landed reports 4, 2, 2. That one-event gap is what a Lambda architecture’s batch path exists to correct. There are two streaming fixes, and each costs something. Widen the lag: run the same events through with a lag of 3 s or 6 s and e7 is still late. It takes 7 s before [0,5) waits for it, and then the window fires at 13.2 instead of 9.3, 3.9 s later. Or keep the window’s state after it fires (“allowed lateness”) and emit a corrected count of 4 when e7 shows up. That means holding state longer, and downstream has to accept a result that changes. Either way you pay in latency or in state for completeness that batch got by waiting.
Cost and trade-offs: staleness against state
Here Time means how old a result can be when someone reads it. Space means what the system has to keep in memory or on disk to produce it.
| Case | Time | Space | Why |
|---|---|---|---|
| Nightly batch | Up to 24 h, plus job runtime | Nothing between runs; re-reads its whole input | Ordering and completeness for free. A rerun recovers from a failure. |
| Hourly batch, 10-minute job | 10 to 70 min old; 40 min on average | Nothing between runs | Staleness = interval + runtime. On average it is half the interval plus the runtime. |
Stream, tumbling window W | Up to W + watermark lag: 7 s in the example | One accumulator per open window, per key | Lag trades freshness for fewer late events. |
| Stream, sliding window | Slide + lag | Each event lands in size ÷ slide windows: a 10-min window sliding every 1 min means 10 | A smaller slide means fresher results, but more state and more output rows. |
Stream–stream join within X | X + lag | Both inputs buffered for X | The buffer is the cost. An unbounded join window means unbounded state. |
| Exactly-once into a transactional sink | Up to one extra checkpoint interval | Periodic snapshots of all operator state | Output commits with each checkpoint, so readers who see only committed data wait for it. |
Batch spends nothing between runs and pays in staleness. Streaming pays continuously, in always-on workers and in state that grows with keys × open windows. The page’s cost crossover tells you when keeping the stream on is cheaper than running batch often. This table tells you what the stream must hold to stay correct once it is on.
Common mistakes
- Windowing on processing time by accident
Restart a job after an hour of downtime and an hour of backlog arrives in a few seconds. With processing-time windows it all lands in one window, and your per-minute chart shows a giant spike and an hour of zeros. Window on the timestamp inside the event unless you really mean “when we saw it”.
- Dropping late events silently
Every watermark is a guess, so some events will arrive after it. Send them to a side output and count them. A late-event rate that creeps up is your signal that the lag is too tight, or that a producer’s clock or buffer has gone wrong. Dropped events that nobody counts look exactly like no events at all.
- Believing “exactly-once” covers side effects
The engine replays from a checkpoint after a failure. State and transactional sinks come out exactly-once. An email sent, a webhook called or a row inserted into a non-transactional store along the way happens again. Make those writes idempotent: key them by event id, or upsert.
- Keyed state with no expiry
A per-user dedupe set or a session map with no TTL grows with every user you have ever seen. It works for weeks, then checkpoints slow down and the job runs out of memory. Give every piece of keyed state a TTL that matches the longest window that reads it.
- Batch jobs that append on rerun
A rerun is only “naturally idempotent” if the job overwrites its output, typically one date partition. An
INSERTthat appends doubles the day’s numbers on the second run. Batch has a lateness edge too. A daily partition sealed at midnight misses yesterday’s events that land at 00:05, unless the job reprocesses a trailing day or two.
Where this shows up in production and interviews
- Fraud, ads and alerting
Card scoring, ad-click counting for budget pacing, and anomaly alerts run on engines like Flink or Kafka Streams. Those are the cases where a result an hour late is worthless. They are also where watermarks, dedupe by event id and late-event handling get designed explicitly.
- The warehouse
Revenue reporting, finance reconciliation and ML training sets are usually scheduled batch jobs, with Airflow running Spark or dbt. They want complete, ordered days, and they want the ability to re-run last Tuesday when a bug is found.
- Change data capture feeding both
A CDC tool such as Debezium turns database writes into a stream. The same stream feeds real-time consumers (a search index, a cache) and lands in the lake for batch models. One source, two freshness tiers, with no dual writes from application code.
- The interview version
“Count ad clicks per minute” or “build a live leaderboard” is really a question about event time versus processing time. Say what your watermark is and what happens to late clicks. Say how you dedupe retries by click id, and whether a nightly batch reconciles the totals that bill customers.
Which would you pick?
Three situations. Pick the side you'd actually build — the explanation follows.
A finance report reconciling yesterday's transactions, read each morning.
The page's test is what happens if this arrives an hour late instead of instantly — here, nothing. Batch also gets ordering and completeness for free by waiting, which is exactly what a reconciliation needs. Running both is the Lambda two-codepath cost for a report nobody reads until morning.
Card-fraud scoring, where a decision made a minute later is a decision made after the money has gone.
When the insight is worthless by the time it arrives, no batch interval is short enough — a 60-second window still authorises a minute of fraud. A review queue catches some of it after the fact, which is a recovery process rather than a detection one.
Why is Kappa gaining ground on Lambda?
Lambda's cost is not compute, it is that the same business logic exists twice in two different frameworks and must be kept in agreement forever — with drift showing up as results that disagree. Kappa treats batch as replaying a window through the streaming path, so the logic lives once. Batch itself is not going anywhere.
Quick answers
Streaming or batch — which should I use?
Ask how fast the value of the result decays. If hours or days of staleness is fine, batch is simpler and cheaper. If the insight needs to act within seconds — fraud, alerting, live UX — you need streaming.
Is streaming just faster batch processing?
No — the core added cost isn’t speed, it’s correctness under disorder. Streaming has to handle events arriving late, out of order, or duplicated in real time, using concepts like event-time, watermarks, and delivery semantics that batch gets for free by simply waiting for a window to close.
What is the Lambda architecture?
Running both a fast streaming path (approximate, real-time results) and a slower batch path (exact, corrected results) in parallel, then reconciling them — used when you need both immediate approximate answers and eventually-correct exact ones.
What is the Kappa architecture?
A simplification of Lambda that pushes everything through a single streaming codepath, treating batch processing as simply replaying a stream over a bounded historical window — avoiding the cost of maintaining the same logic twice in two different systems.
Streaming vs Batch: a photo, or a live feed?
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Handbooks
- The Kafka HandbookApache Kafka as a distributed append-only log, not a queue — topics, partitions and offsets, producers, consumers and consumer groups, per-key ordering, replication and ISR, delivery semantics (at-least-once and exactly-once), retention vs log compaction, and when Kafka beats a message queue.Read →
- Kafka vs RabbitMQThey both "move messages", which is exactly why teams pick the wrong one. Kafka is a durable, replayable log where consumers track their own offset; RabbitMQ is a smart broker that routes each message and deletes it on ack. The remember-vs-forget core difference, throughput and ordering trade-offs, and how to choose.Read →
- The WebSockets & Real-Time HandbookWhy "live" is hard on a protocol that can't push. Polling makes you wait on average half the interval to learn of an event (a 10s poll = ~5s staleness) and wastes a request every time nothing changed — and shrinking the interval only multiplies the waste. A WebSocket keeps one persistent full-duplex line open so the server pushes the instant something happens: latency ≈ one network hop, zero empty requests. The poll-vs-push latency math, when to use SSE instead, and the stateful-scaling pitfalls. With worked math and runnable code.Read →
- Kafka vs KinesisSame partitioned-log model underneath, different operational surface: Kafka is self-run and portable with a huge ecosystem; Kinesis is fully AWS-managed with a hard per-shard throughput ceiling. Retention, cost model, and the lock-in trade-off.Read →
- REST vs Webhooks vs SSEThree ways client and server move data, split by who exposes an endpoint and whether the connection stays open: REST pulls, webhooks flip who runs the server, SSE keeps one connection open for a live push. How real systems run all three at once.Read →
- Monolith vs MicroservicesMicroservices don’t remove complexity, they relocate it from the codebase into the network. Why the real trigger to split is organizational (Conway’s Law), not code size, and why "monolith first" is the pattern behind most successful splits.Read →