Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

Handbooks  /  Streaming vs Batch
Engineering~8 min readComparison
Head to Head

Streaming vs batch: is being fast worth the cost?

StreamingvsBatch

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.

01

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.

→ The rule

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.

02

Head to head

DimensionStreamingBatch
LatencySub-second to secondsMinutes to hours/days — as fresh as the last run
ComplexityHigher — disorder, windowing, exactly-once semanticsLower — deterministic, easy to reprocess/backfill
Cost modelNeeds always-on infrastructureCan use cheap scheduled/spot compute
Failure recoveryCheckpointing / replay from an offsetRerun the job — naturally idempotent
Use case shapeFraud detection, live dashboards, alertingEnd-of-day reports, ETL, large aggregate analytics
ToolingKafka Streams, Flink, Spark Structured StreamingSpark, Airflow, dbt
03

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
04

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.

→ The modern default

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.

05

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.

→ The trade you’re actually making

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.

06

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.

→ The pattern generalizes

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.

→ The number

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

The picture: event-time windows and a late event

[0,5) s[5,10) s[10,15) s e1@1.2 e2@3.5 e4@7.0 e3@6.1 e5@9.3 e6@11.4 e8@13.2 e7 @12.0 051015 322 422 watermark = max event time seen − 2 s; a window fires when it reaches the end watermark 9 on timelatet (s) streambatch
Each box sits at the moment its event happened (event time). The @ 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.
By the numbers

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 atEventEvent timeWindowMax seenWatermarkWhat happens
1.2e11[0,5)1−1Counted
3.5e23[0,5)31Counted
6.1e36[5,10)64Counted
7.0e44[0,5)64Out of order, but [0,5) is still open (4 < 5): counted
9.3e59[5,10)97Counted. 7 ≥ 5, so [0,5) fires: 3
11.4e611[10,15)119Counted
12.0e72[0,5)119Late. [0,5) already fired: dropped or sent to a side output
13.2e813[10,15)1311Counted. 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.

Trade-offs

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.

CaseTimeSpaceWhy
Nightly batchUp to 24 h, plus job runtimeNothing between runs; re-reads its whole inputOrdering and completeness for free. A rerun recovers from a failure.
Hourly batch, 10-minute job10 to 70 min old; 40 min on averageNothing between runsStaleness = interval + runtime. On average it is half the interval plus the runtime.
Stream, tumbling window WUp to W + watermark lag: 7 s in the exampleOne accumulator per open window, per keyLag trades freshness for fewer late events.
Stream, sliding windowSlide + lagEach event lands in size ÷ slide windows: a 10-min window sliding every 1 min means 10A smaller slide means fresher results, but more state and more output rows.
Stream–stream join within XX + lagBoth inputs buffered for XThe buffer is the cost. An unbounded join window means unbounded state.
Exactly-once into a transactional sinkUp to one extra checkpoint intervalPeriodic snapshots of all operator stateOutput 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.

Watch for

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 INSERT that 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.

In the wild

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.

Your call

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.

Card-fraud scoring, where a decision made a minute later is a decision made after the money has gone.

Why is Kappa gaining ground on Lambda?

Frequently asked

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.

▶  Watch it explained

Streaming vs Batch: a photo, or a live feed?

Streaming vs Batch · Vibe Engines · 2026
Finished this one? 0 / 209 Handbooks done
NextOrchestration vs Choreography Next on the “Moving data between services” ladder · rung 5 of 6

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Handbooks