27. Micro-batch: a stream as small batches
Micro-batch processes a stream as a sequence of small batches: every few seconds or minutes, it reads what has arrived since the last batch, processes it and commits. Each batch pays a fixed overhead, so the interval trades freshness against cost; and it is a valid way to implement streaming, not a lesser one.
The clip cuts the morning's ten claims into batches by a trigger every five minutes. Each batch reads the claims that arrived since the previous trigger and pays twenty seconds of fixed work (planning, reading the offsets, committing the checkpoint) plus two seconds per claim; a trigger with nothing new starts no batch. Then the same claims at one, five and ten minutes: more batches and more overhead as the interval shortens, staler results as it grows.
The intuition: the lift, not the stairs
Harbour Mutual's claims handlers search the claims index all day, and want a new claim to be findable within a few minutes. The search index takes updates in bulk and throttles single writes. Writing each claim the moment it arrives would be the stairs, one step at a time; collecting what has arrived and sending it every few minutes is the lift.
A lift that leaves every ten seconds is nearly as quick as the stairs but runs almost empty; one that leaves every ten minutes is full and slow. Each trip has a fixed cost whatever it carries. Micro-batch is choosing how often the lift leaves.
How it works, step by step
A trigger fires every interval. The job asks the log which events arrived since the offsets it last committed, reads exactly those, processes them together and commits the new offsets with the results. If nothing arrived, no batch runs.
Each batch pays a fixed overhead whatever its size: planning the work, reading and recording offsets, writing the checkpoint and the output. Here that is 20 seconds a batch, and the events themselves cost 2 seconds each. Fewer, larger batches spend less of their time on overhead.
An event waits for the next trigger and then for its batch to finish, so its latency is between the batch's duration and the interval plus the duration. Halving the interval roughly halves the wait, and roughly doubles the number of batches when events are spread out.
Because each batch reads a recorded range of offsets and commits its output with the new offsets, a failed batch is simply run again on the same range: the batch is idempotent when its output is written by key. That is why micro-batch gives the same correctness as event-at-a-time processing, state and watermarks included, with simpler recovery.
| Interval | Batches | Overhead | Work | Average wait | Longest wait |
|---|---|---|---|---|---|
| 1 min | 8 | 160 s | 20 s | 57 s | 1 min 21 s |
| 5 min | 5 | 100 s | 20 s | 3 min 17 s | 5 min 23 s |
| 10 min | 3 | 60 s | 20 s | 4 min 49 s | 8 min 54 s |
By hand
Cut the ten events into batches with a trigger every five minutes, twenty seconds of overhead a batch and two seconds a claim.
| Event | Claim | Policy | Reported | Reached the log | Amount | Note |
|---|---|---|---|---|---|---|
| E01 | C-201 | P-1001 | 09:01:40 | 09:02:10 | €1,200 | – |
| E02 | C-202 | P-1002 | 09:04 | 09:04:50 | €2,400 | – |
| E03 | C-203 | P-1003 | 09:06:30 | 09:07:45 | £800 | health details |
| E04 | C-204 | P-9999 | 09:09 | 09:09:40 | €650 | – |
| E06 | C-206 | P-1006 | 09:14:20 | 09:15:05 | €950 | – |
| E07 | C-207 | P-1007 | 09:14:50 | 09:15:12 | €4,200 | – |
| E08 | C-208 | P-1008 | 09:15 | 09:15:20 | €700 | – |
| E09 | C-209 | P-1009 | 09:18:30 | 09:19:10 | €1,500 | – |
| E05 | C-205 | P-1005 | 09:12:10 | 09:21:30 | €3,100 | – |
| E10 | C-210 | P-1010 | 09:24 | 09:25:40 | €2,600 | – |
- The first trigger fires at 09:05. Which events does it read, and how long does the batch take?
Predict the result, then check it
E01 and E02: 20 seconds of overhead and 4 of work, so 24 seconds; it commits at 09:05:24. - E01 reached the log at 09:02:10. How long did it wait to be readable?
Predict the result, then check it
3 min 14 s: until the trigger, then the batch. - Nothing arrives between 09:10 and 09:15. What does the trigger at 09:15 do?
Predict the result, then check it
It starts no batch: the morning has 5 batches, not 6. - How much overhead does the morning cost at five minutes, and at one minute?
Predict the result, then check it
100 seconds at five minutes, 160 at one minute, for the same 20 seconds of work. - What share of the compute is overhead at five minutes?
Predict the result, then check it
83.3%: 100 of 120 seconds.
What you found: At five minutes a claim waits 3 min 17 s on average for 100 s of overhead; at one minute, 57 s for 160 s. Freshness is bought with overhead.
- Read exactly the offsets since the last commit
- Without it: A batch re-reads or skips events, and totals drift.
- Commit the output with the new offsets
- Without it: A batch that fails after writing is run again and writes its output twice.
- Start no batch when nothing arrived
- Without it: An idle stream pays the full overhead every interval for nothing.
- Choose the interval from the reader's need
- Without it: A one-second trigger costs many times the overhead for a reader who looks every ten minutes.
- Micro-batch is not real streaming.
- In fact: It reads the same log, keeps the same state and watermarks, and recovers from the same checkpoints; only the unit of work is a small batch. It is a valid way to implement streaming.
- A shorter interval is always better.
- In fact: At one minute the morning costs 160 s of overhead against 60 s at ten minutes, for claims that wait 57 s instead of 4 min 49 s.
- Micro-batch is the same as a nightly batch run often.
- In fact: A nightly batch reprocesses a period; a micro-batch reads only the new offsets and carries its state from batch to batch.
When it fits, and when it does not
- Fits: freshness of seconds to minutes, sinks that prefer bulk writes (search indexes, warehouses, Delta tables), and teams that want simple recovery.
- Does not fit: decisions needed in well under a second, where even a short batch is too slow (page 26).
Design notes
Set the interval from the freshness the reader needs, then check that a batch finishes well within it; a batch that takes longer than its interval means the job is falling behind. Write the output by key so a retried batch replaces what it wrote.
Why it matters
Most streaming on lakehouse platforms is micro-batch, and that is a choice, not a compromise. Saying "minutes are enough, so we run a five-minute trigger" often halves a platform's cost compared with an always-on job polling continuously.
On Azure (checked against Microsoft Learn on 24 October 2026)
- Azure Databricks Structured Streaming calls a fixed-interval trigger
processingTime; without one it checks for new data continuously, which Microsoft warns can cost many storage calls. - AvailableNow processes everything available as an incremental batch and stops: micro-batch run on a schedule.
Where it goes wrong
- The default trigger left on. The job checks for data every few milliseconds and the storage bill grows.
- Batches longer than the interval. The job falls further behind with every trigger.
- Appending output. A retried batch writes its rows twice.
- Tiny files. A one-second trigger writing to a lake leaves thousands of small files that slow every query.
- Cut a stream into micro-batches by hand and compute each event's wait.
- Compute a schedule's overhead and the share of compute it takes.
- Explain why micro-batch is a valid way to implement streaming.
- Choose a trigger interval from the reader's freshness need.
Check yourself
Choose an answer to each question, then press Check.
Sources
The works this page draws on, summarised in its own words rather than quoted. Read them for the full argument.
- M. Zaharia et al., "Discretized Streams: Fault-Tolerant Streaming Computation at Scale", SOSP 2013A stream as a series of small, deterministic batches, and recovery by recomputation.
- Apache Spark 4.0 documentation: Structured Streaming Programming GuideMicro-batch execution, triggers, checkpoints and offsets.
- Microsoft Learn: Configure Structured Streaming trigger intervals (Azure Databricks)processingTime, AvailableNow and real-time mode, and the cost of the default trigger.
Practise it
The chapters that put this theory to work on Harbour Mutual and Kestrel:
- Chapter 30: Lambda and Kappa: architectures for streaming
- Chapter 31: Pipeline patterns: choosing and combining
The tools to try it in:
- Pipeline patterns lab · Run the same claim events through eight pipeline patterns and see latency, overhead, a consumer failing, a delivery repeated and a logic change replayed.
- Stream lab · Run one claims feed as batch, Lambda and Kappa side by side, inject a late correction and replay the log.
Terms taught here: Micro-batchTrigger interval