Batch Inference
Advanced 15 min read Batch Inference

Mini-Batch and Windowed Processing

Freshness you can schedule, not stream

Mini-batch is the middle ground: process data in small windows (minutes) instead of nightly or per-event, trading a little freshness for throughput. Window semantics — size, watermark, trigger — decide how fresh and how correct the scores are.

mini-batchwindowmicro-batchwatermarkstreaming batchfreshness
Before we start

What you will learn

  • Place mini-batch between pure batch and streaming
  • Choose window size, watermark and trigger semantics
  • Bound correctness vs freshness tradeoffs near real-time
Introduction

What is this?

Mini-batch processing scores small windows of recently-arrived data every few minutes rather than nightly: a stream-like flow with a batch mindset. Windows define grouping, watermarks define how late data is handled, and triggers decide when a window's results are emitted.

Motivation

Why do you need it?

  • Not everything needs sub-second answers, but nightly is too stale for churn or fraud intent.
  • Mini-batch reuses batch tooling (Spark, Flink) with bounded windows.
  • It's easier to retry and audit than true streaming.
  • Throughput stays high because you still amortize model loads over windows.
Think about it

Mental model

Imagine

A school bus doing rounds every 15 minutes instead of a taxi per kid

Think of

Mini-batch windows

Kids arriving in the window (cars) board one bus (batch). If you set the schedule short, kids wait less but buses run almost empty; long, and they wait long. The route (window + trigger) sets the freshness/cost tradeoff.

Mechanics

How it works

  • Data is grouped by a window boundary (e.g. every 5 minutes by event time).
  • A watermark marks how late data may be before the window closes.
  • When the trigger fires, the window's rows are scored and written.
  • Late rows after watermark go to a side channel for reconciliation.
  • Scores are written per window, addressable and monitored like batch runs.

Windowed mini-batch scoring.

Events
Window the flow
Watermark
Trigger
Score + write
Real world

In production

  • A fraud system scores 5-minute windows of transactions, catching patterns that nightly misses.
  • A forecasting job emits hourly windows that a streaming dashboard reads.
  • A recommendation service re-scores trending items every 10 minutes from a mini-batch join.
Guidelines

Best practices

  • Choose window size from the business freshness, then cost it.
  • Set watermarks deliberately — too tight drops late data, too loose delays output.
  • Make triggers explicit: processing-time vs event-time windows.
  • Record window boundaries in output metadata for reconciliation.
Watch out

Common mistakes

  • Window size chosen by cluster capacity, not freshness need.
  • Ignoring watermarks — late events silently vanish, and scores look 'off' later.
  • Treating mini-batch as streaming and debugging with streaming assumptions.
  • Writing overlapping windows, double-counting entities.
When things break

Debugging tips

  • Scores lag wall-clock — event-time vs processing-time skew; align your watermark/trigger.
  • 'Missing' rows — they arrived past the watermark; check the late channel, not the window.
  • Outputs differ from nightly — windowed aggregation at 5-min vs nightly sees different partial states.
Interviews

Interview checkpoint

Practice

Hands-on lab

Score Windowed Mini-Batches
40 min · advanced
In progress
Objectives
  • Group events into event-time windows
  • Apply watermark semantics to late data
  • Emit per-window outputs with boundaries

Score Windowed Mini-Batches

40 min · advanced

0/3 steps
0%
sandbox · Linux sandbox
$
Try these commands
Test yourself

Quick quiz

0/2
1

Mini-batch's core advantage over pure batch is…

2

Events arriving after a window's watermark are automatically included for free.

Go deeper

Official documentation