Skip to content
Bronze 6 min read · System design 2 practice problems ↓

Batch, micro-batch or streaming?

Before writing a stream, ask whether you need one. Most data does not need to be fresh to the second, and a stream costs more to run and to get right than a nightly job. This lesson gives you the three ways to process data, what each costs, and a checklist for the question every data engineering design interview asks.

Step 4 · Structured Streaming · Bronze · First streams, lesson 1 of 5

Read first: Transformations vs actions (skip if you know it)

In plain words first

Think of three ways to get your post:

The postman, once a day

Everything that arrived since yesterday comes in one delivery. Cheap and simple, but a letter can wait a day. That is batch.

A courier every 15 minutes

Whatever piled up since the last round comes over in a small bundle. Fresher, and someone has to keep doing rounds. That is micro-batchmicro-batch: One small round of a stream: Spark takes the data that arrived since the last round, processes it like a little batch job, and saves its progress. Learn more →.

A phone call

Each message reaches you the moment it is sent. Fastest, and you must always be ready to answer. That is record-at-a-time streaming.

None is better in general. The right one depends on how soon the message is needed, and what you are willing to pay for that.

Three ways to process data

BatchMicro-batchRecord at a time
How it runsA scheduled job reads a whole period, such as yesterdaySmall batches of whatever is new, every few seconds or minutesEach event is processed as it arrives
Typical freshnessHours to a daySeconds to minutesMilliseconds
ExamplesAn Airflow DAGDAG: Directed acyclic graph: the plan of steps Spark builds for a job, from reading data to the result. Learn more → running Spark or dbtSpark Structured StreamingFlink, KafkaKafka: A system that stores streams of events in topics, in order within each partition, so many readers can read them, and read them again, at their own pace. Learn more → Streams, Dataflow

Structured Streaming is micro-batch by default, with latencies as low as about 100 milliseconds. The same code also covers batch: with trigger(availableNow=True) on a schedule it processes only what is new and stops (Triggers). Its experimental continuous mode goes down to about a millisecond, for simple queries only, at-least-onceat-least-once: No event is lost, but after a failure some can be processed or written twice. Learn more →.

Turn "real time" into a number

"Real time" means 200 milliseconds to a payments team and 15 minutes to a marketing team. Ask what decision the data feeds, and how late it can be before that decision gets worse:

Use caseFresh enoughChoice
Finance report for the morning meetingBy 8 amBatch, nightly
Orders dashboard for operations10-15 minutesMicro-batch: availableNow every 10 minutes
Alert when a delivery van stops reportingAbout a minuteMicro-batch, always on
Block a fraudulent card paymentBefore approval, well under a secondRecord at a time, often inside the payment service

What freshness costs

Compute

A nightly job pays for an hour; an always-on stream pays for every hour of the day, busy or not.

Complexity

State, watermarks, late datalate data: Events that arrive after newer events have already been seen, for example from a phone that was offline. Learn more →, duplicates and exactly-onceexactly-once: Each event affects the output exactly one time, even when work is retried after a failure. Learn more → only exist because the data never stops. Batch recomputes a whole day cleanly.

Operations

A stream that stops at 3 am is stale at 3 am. Someone is on call, with monitoring, checkpointscheckpoint: In streaming, the folder where Spark records which input it has processed and its state, so a restarted query continues where it stopped. Learn more → and safe restarts.

Corrections

Late events change results that were already written. Many teams pair a stream with a nightly batch job that corrects the day.
Tip: the sourcesource: Where a stream reads from: a Kafka topic, a folder of files, a Delta table. Learn more → caps freshness. If partners drop files once an hour, a millisecond engine still delivers hour-old data. Check where the data comes from before choosing how to process it.

A checklist for the interview

  1. 1
    Ask for the freshness needed, as a number, and what happens when data is late.
  2. 2
    Check the source: an event log (Kafka, Pub/Sub, a database change feed) can be streamed; files that land hourly cap you at an hour.
  3. 3
    Hours or a day: batch. Say why it is enough.
  4. 4
    Minutes: micro-batch. Scheduled availableNow runs if the interval is long compared with job start-up; an always-on stream if not.
  5. 5
    Seconds or per-event decisions: an always-on stream, and a record-at-a-time engine when it must be well under a second.
  6. 6
    Name the costs you accept and how you will correct late data, reprocess and backfill.

Common mistakes

  • Choosing streaming because it sounds modern — An always-on cluster and an on-call rota for a report read once a day.
  • Accepting "real time" without a number — Ask what decision the data feeds and how late it can be.
  • Ignoring how often the source delivers — A fast engine on hourly files still gives hour-old data.
  • Forgetting corrections — Late events change streamed results. Plan the batch job that fixes them.

Key takeaways

  • Batch processes a period on a schedule, micro-batch processes what is new every few seconds or minutes, streaming handles each event as it arrives.
  • Turn "real time" into a number by asking what decision the data feeds.
  • Each step towards fresher data adds compute, complexity, on-call and corrections.
  • The source caps freshness; Spark covers batch and micro-batch with one codebase.

Interview prep

THE QUESTION

"The business wants a real-time sales dashboard. Batch, micro-batch or streaming?"

I would first ask what "real time" means for them: who looks at the dashboard, and what they do differently if it is 30 seconds or 15 minutes old. For an operations dashboard, 5 to 15 minutes is usually enough, so I would use micro-batch: a Spark Structured Streaming job from the orders topic into a Delta or BigQuery table, run with availableNow every 10 minutes, which costs a fraction of an always-on cluster and keeps exactly-once bookkeeping. If they need seconds, the same code runs always on. Record-at-a-time engines only earn their complexity under a second, such as fraud checks. Either way I would add a nightly batch job that recomputes the day, to correct late orders and refunds.

Avoid: "streaming, because it is real time" without asking how fresh the data must be, or naming what an always-on stream costs.

Follow-ups · answer out loud, then open

Follow-up"When is a record-at-a-time engine like Flink worth it over Spark micro-batches?"
When the decision has to happen well under a second, per event: fraud checks before a payment is approved, or alerts that must fire immediately. Spark micro-batches reach latencies of around 100 milliseconds at best and usually run at seconds or minutes, which covers most analytics. Flink earns its extra operational complexity only when that gap matters.
Scenario"A team runs an always-on stream for a report that executives read every morning. What would you change?"
Keep the same Spark code but run it with trigger(availableNow=True) once or a few times a night from the scheduler. The checkpoint still gives exactly-once incremental processing, the cluster runs only while there is work, and nobody needs to be paged at 3 am for a report read at 9.
Trap"Streaming is always more accurate because the data is fresher."
Fresher, not more accurate. Streamed results change as late events, refunds and corrections arrive, and a stream has to decide when a window is final. A batch job over a closed day sees all the data at once. That is why many designs pair a stream for freshness with a nightly batch job for correctness.

Check yourself

3 questions

Operations need an orders dashboard at most 15 minutes old. What fits best?

Show the answer

A Spark stream with availableNow every 10 minutes. Minutes of freshness without paying for an always-on cluster.

Partner files land once an hour. How fresh can the results be?

Show the answer

About an hour, whatever the engine. The source delivers hourly, so nothing downstream can be fresher.

What is Spark Structured Streaming's default execution model?

Show the answer

Micro-batch. Micro-batch by default; continuous processing is experimental.

Practise this

Interview problems on streaming, graded on hidden tests

Keep going

Up next · First streams · lesson 2 of 5 · 8 min read
Structured Streaming basics
Streams as an unbounded table: sources, sinks, triggers, output modes and checkpoints.

Related lessons

Primary sources: Structured Streaming overview (micro-batch and continuous processing) · Triggers