Model Deployment
Intermediate 14 min read Model Deployment

Batch Inference

Score the whole table, calmly

Batch scoring is the workhorse for bulk decisions: pull data, score in parallel, write results. Orchestrated as scheduled jobs with idempotency, watermarking and failure retries — cheap, auditable, deterministic.

batchscheduled jobidempotentwatermarkorchestrationretryaudit
Before we start

What you will learn

  • Design batch jobs: input slices, idempotency, ordering
  • Make failures retryable and results auditable
  • Keep batch/online scoring on the same features
Introduction

What is this?

Batch inference scores a dataset on a schedule (nightly, hourly) instead of per-request. Jobs pull the input partition (e.g. customers updated since watermark), run the model over rows in parallel, and write predictions back with metadata (job id, model version, run timestamp). Idempotency means re-runs overwrite the same keys without side effects; failure handling retries failed partitions; and every output row carries lineage for audits.

Motivation

Why do you need it?

  • Massively cheaper per prediction than online at equal volume.
  • Deterministic and testable — a batch run is reproducible on the same data + version.
  • Fits upstream data cadence: daily features → daily scores.
  • Simple to justify: one pipeline, one manifest, one retry policy.
Think about it

Mental model

Imagine

A mailroom sorting the night's letters by a route sheet

Think of

Scheduled batch scoring

Every night the same clerk (the job) opens the same mailbag (input partition), stamps each letter with the route — and if a bag tears, re-ran only that bag, never the whole post office. Letters sorted yesterday don't get re-done; the route sheet (job manifest) records which bags were done when.

Mechanics

How it works

  • Define the input: table + partition predicate (updated_at ≥ watermark).
  • Score in parallel; rows are independent → embarrassingly parallel across workers/partitions.
  • Write outputs with a key: (business key, job id, model version) — idempotent by key.
  • Orchestrate: airflow/dagster/scheduler triggers on data readiness + monitors freshness.
  • Retry semantics: failed partitions retried; successes never re-scored; results row-pinned to version.

Scheduled job: pull, score, write with lineage.

Trigger
Pull slice
Score rows
Write + lineage
Verify
Real world

In production

  • Nightly credit-risk portfolio scores into the data warehouse.
  • Hourly churn-risk scores feeding campaign systems.
  • On-demand re-scores of a whole segment after policy/data changes.
Guidelines

Best practices

  • Make runs idempotent: same input → same output rows, safe to re-run.
  • Watermark + partition: only score changed rows; keep a 'last scored' registry.
  • Log a job manifest (input range, model version, row count, duration) for every run.
  • Reuse feature code with the online path to avoid skew.
Watch out

Common mistakes

  • Re-scoring everything each run (cost grows with the whole table, not the delta).
  • Non-idempotent writes — a retry appends duplicates.
  • Unversioned outputs breaking downstream joins.
  • No row-count/freshness check, so a silently empty run ships 'no scores'.
Root cause analysis

Common issues

Error
Retry produced duplicates
Root cause

Write wasn't idempotent by key

Fix

Upsert on (business key, model version); never append blindly.

Error
Empty output despite big input
Root cause

Filter predicate bug or watermark drift

Fix

Assert row counts (input vs output delta); alert on mismatch thresholds.

Error
Job costs explode weekly
Root cause

Full-table rescore with no watermarking

Fix

Partition by update watermark; score only the delta; archive full rescans to on-demand only.

When things break

Debugging tips

  • Diff two consecutive runs on overlapping rows; deltas should match ONLY where inputs changed.
  • Alert on row-count sudden drops to zero — a silent-empty batch is a production disaster.
  • Time the job at max historical partition; failure-driven boundary > happy-path boundary.
  • Correlate batch output with online scores on a shared sample as a permanent skew check.
Interviews

Interview checkpoint

Test yourself

Quick quiz

0/2
1

Idempotent batch writes mean:

2

Batch jobs should score the entire table every run for freshness.

Go deeper

Official documentation