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
On this page
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
A courier every 15 minutes
A phone call
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
| Batch | Micro-batch | Record at a time | |
|---|---|---|---|
| How it runs | A scheduled job reads a whole period, such as yesterday | Small batches of whatever is new, every few seconds or minutes | Each event is processed as it arrives |
| Typical freshness | Hours to a day | Seconds to minutes | Milliseconds |
| Examples | An 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 dbt | Spark Structured Streaming | Flink, 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 case | Fresh enough | Choice |
|---|---|---|
| Finance report for the morning meeting | By 8 am | Batch, nightly |
| Orders dashboard for operations | 10-15 minutes | Micro-batch: availableNow every 10 minutes |
| Alert when a delivery van stops reporting | About a minute | Micro-batch, always on |
| Block a fraudulent card payment | Before approval, well under a second | Record at a time, often inside the payment service |
What freshness costs
Compute
Complexity
Operations
Corrections
A checklist for the interview
- 1Ask for the freshness needed, as a number, and what happens when data is late.
- 2Check the source: an event log (Kafka, Pub/Sub, a database change feed) can be streamed; files that land hourly cap you at an hour.
- 3Hours or a day: batch. Say why it is enough.
- 4Minutes: micro-batch. Scheduled availableNow runs if the interval is long compared with job start-up; an always-on stream if not.
- 5Seconds or per-event decisions: an always-on stream, and a record-at-a-time engine when it must be well under a second.
- 6Name 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?"
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?"
Scenario"A team runs an always-on stream for a report that executives read every morning. What would you change?"
Trap"Streaming is always more accurate because the data is fresher."
Check yourself
3 questionsOperations 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 readStructured Streaming basics
Streams as an unbounded table: sources, sinks, triggers, output modes and checkpoints.
Related lessons
TriggersStructured Streaming · 7 min read
Incremental file ingestion
Primary sources: Structured Streaming overview (micro-batch and continuous processing) · Triggers