Skip to content
Tech Interview Prep
Technical interview guide

Batch vs. Streaming Processing

Processing data in scheduled chunks versus continuously as it arrives, and the latency/complexity tradeoff.

Minutes to read
3
Practice MCQs
25
Interview Q&A
25
Edition
v5
Editorial status
Reviewed

Scope: Apache Flink stable/current 2026-08-31; Apache Spark 4.2; Apache Beam, Kafka, Iceberg, OpenLineage current 2026-08-31.

Overview

Curated: · Written: · Reviewed:

Batch vs. Streaming Processing

In one line

Batch computes a result once over a complete, bounded input. Streaming keeps results updated as an unbounded stream arrives. Choose streaming when a decision must change within seconds or minutes, and accept watermarks, state and corrections as the cost.

Key definitions

  • Event time: when the business event happened. Windows built on it give the same result on replay.
  • Processing time: when the operator handled the record. Only correct for actions tied to arrival.
  • Watermark: the engine's estimate of event-time progress. A heuristic, not a guarantee that no earlier event is still in flight.
  • Allowed lateness: how long a fired window keeps state so late records can update it. Flink's default is 0.
  • Trigger and accumulation mode: when a pane is emitted, and whether later panes replace, retract or add to earlier ones.
  • Checkpoint: a consistent snapshot of source offsets and operator state that a restart resumes from.

Formulas and complexity

watermark=max⁡(event time seen)−out-of-orderness bound\text{watermark} = \max(\text{event time seen}) - \text{out-of-orderness bound} window [s,e) fires when the watermark passes e\text{window } [s, e) \text{ fires when the watermark passes } e window state is dropped when the watermark passes e+allowed lateness\text{window state is dropped when the watermark passes } e + \text{allowed lateness}

Hypothetical figures: the maximum event time seen is 12:00:40 and the bound is 90 s, so the watermark is 11:59:10. The window [11:58:00, 11:59:00) has passed its end and fires. With allowed lateness of 120 s, its state survives until the watermark reaches 12:01:00. A record stamped 11:58:30 that arrives while the watermark is below 12:01:00 updates that window and emits a corrected pane.

How it works

  1. Each record is assigned to windows by its event timestamp, not its arrival time.
  2. The watermark advances with the maximum event time seen, minus the out-of-orderness bound.
  3. When the watermark passes a window end, the window fires and emits its result.
  4. A record for a window already past its allowed lateness goes to a side output or is dropped. It is never silently merged.
  5. Checkpoints store offsets and state together, so a restart replays only what the sink has not committed.
no yes Kafka source Assign event-time windows Watermark = max event time minus bound Watermark passed window end? Fire window result Keep state for allowed lateness Transactional or idempotent sink

When to use and when not to

FactorBatchStreaming
Freshness neededHours, complete periodSeconds to minutes
Late dataReprocess the full periodCorrections through lateness and triggers
Final numbersSimple, complete inputNeeds a watermark policy and reconciliation
Failure recoveryRerun the jobCheckpoints, offsets and sink commits
Operating costScheduled, cheap to rerunAlways on; state and backpressure to watch
Typical useSettlement reports, training, restatementFraud response, monitoring, personalization
Only a small subset needs seconds-level latencyBatch everything and accept the lagStream the subset, batch the full history

Traps interviewers probe

  1. Running a batch group-by over an out-of-order stream. Fix: use event-time windows, set the watermark bound from disorder you measured on real data (90 s in the example above), and set allowed lateness or a side output for records beyond it.
  2. Treating the watermark as proof. Fix: call it a heuristic. Decide what happens to late records and who accepts the correction.
  3. Assuming exactly-once engine state means exactly-once effects. Fix: checkpoints restore engine state, but a non-idempotent sink still receives replayed records. Use a stable event identity as the idempotent key, or a two-phase-commit sink.
  4. Building keys from arrival time or System.currentTimeMillis(). Fix: derive keys from the event identity, so a replay writes the same row.
  5. Fixing a hot key by adding partitions. Fix: one key stays on one subtask. Split the key with salting or pre-aggregation, and check per-subtask CPU.

Interview tips

Open with the decision: "The freshness and correctness requirements decide it. I would keep one durable log, stream the subset that needs seconds, and batch-restate the full day."

Follow-ups to expect:

  • What watermark bound did you choose, and how did you measure the disorder?
  • What happens to a record that arrives after its window fired?
  • Where does exactly-once stop, and what does the sink do on replay?
  • Kappa or Lambda for historical reprocessing? Kappa replays the log; Lambda keeps a separate batch path.
  • Which lag and watermark metrics page on-call?

30-second answer outline:

  1. Name the decision and the freshness it needs (5 s).
  2. Choose event time with a watermark bound set from measured disorder (8 s).
  3. Say what happens to late data and who accepts corrections (7 s).
  4. State the end-to-end guarantee: checkpoint plus idempotent or transactional sink (6 s).
  5. Name two SLIs: event-time lag and consumer lag (4 s).

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.