Fikkie.
← All posts

Chunked batch processing for large datasets

Why processing data in slices instead of one giant pass made syncs 60–80% faster and far more reliable.

Article

When a sync job has to process a dataset that doesn’t fit comfortably in memory — or in one transaction — the naive approach fails in predictable ways. The job runs too long, uses too much memory, and dies partway through, leaving the database in an inconsistent state. That’s exactly the problem chunked batch processing solves.

The problem with the one-shot approach

A single pass over a large table means one long-running job. Long-running jobs are a hazard: a failure halfway through requires either a full restart or messy partial-recovery logic, and a big transaction holds locks on everything it touches.

Chunking changes the failure model

By processing the dataset in bounded slices — say a few hundred rows at a time — each chunk becomes an independent unit of work. If a chunk fails, it can be retried in isolation without redoing everything. The gains compound:

  • Memory stays flat. You only ever hold one chunk in memory.
  • Locks are short-lived. Each chunk commits quickly instead of holding a giant transaction.
  • Failures are cheap. One bad row only wastes one chunk, not the whole job.

Ordering matters

Some of my data flows were order-sensitive, which chunking doesn’t solve on its own. For those I paired chunked processing with FIFO queue logic, so chunks were consumed in the exact order they were enqueued. The combination gave me speed and determinism.

The numbers

On the datasets I worked with, chunked batch processing accelerated operations by 60–80% while making the sync noticeably more reliable. The mechanism is simple — it’s the discipline of doing the same work in smaller, safer pieces.