Theory · Page 27 of 34 · Pipeline patterns

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 stream as a series of small batches
Playback speed

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.

Remember Micro-batch reads what arrived since the last trigger, processes it as one small batch and commits; the interval sets freshness and overhead together.

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.

The same ten events at three intervals (computed)
IntervalBatchesOverheadWorkAverage waitLongest wait
1 min8160 s20 s57 s1 min 21 s
5 min5100 s20 s3 min 17 s5 min 23 s
10 min360 s20 s4 min 49 s8 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.

The ten events, with the time each reached the log
EventClaimPolicyReportedReached the logAmountNote
E01C-201P-100109:01:4009:02:10€1,200–
E02C-202P-100209:0409:04:50€2,400–
E03C-203P-100309:06:3009:07:45£800health details
E04C-204P-999909:0909:09:40€650–
E06C-206P-100609:14:2009:15:05€950–
E07C-207P-100709:14:5009:15:12€4,200–
E08C-208P-100809:1509:15:20€700–
E09C-209P-100909:18:3009:19:10€1,500–
E05C-205P-100509:12:1009:21:30€3,100–
E10C-210P-101009:2409:25:40€2,600–
  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.

Why this step
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.
People often think…
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.
You can now…
  • 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.

1. At a five-minute trigger, how many batches does the morning need?
2. What happens to overhead when the interval is cut from ten minutes to one?
3. Why can a failed micro-batch simply be run again?
Answer every question first.

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:

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

An unhandled error has occurred. Reload 🗙

Reconnecting…

Your connection to the Cloud Data Architecture Lab dropped, probably a Wi-Fi blip. Hold on while it reconnects.

The connection could not be restored. The page will reload in a few seconds.