Part 22 · Applications

Spring Batch: chunk commits and safe restarts

Prerequisites: 01-ecosystem

What survives a batch failure?

ItemReader: read records; ItemProcessor: transform / filter; ItemWriter: write chunk; Chunk commit: durable boundary; JobRepository: execution metadata. Connections: ItemReader to ItemProcessor (items); ItemProcessor to ItemWriter (chunk items); ItemWriter to Chunk commit (commit interval); Chunk commit to JobRepository (record progress)
Conceptual chunk and metadata responsibilities; transaction participation depends on actual repository/resource configuration. [S41] [S42]

Which work remains after a failed chunk?

Chunks 1–7: committed work; Chunk 8: failed / rolled back; Restart: resume per contract; Execution metadata: saved progress. Connections: Chunks 1–7 to Chunk 8 (later processing); Chunk 8 to Restart (new execution); Execution metadata to Restart (restart state)
Conceptual restart boundary. Stable input, restartable components and durable metadata are required; external effects need idempotency. [S41] [S42]

Goal & mental model verified

A Job contains Steps; chunk-oriented processing reads items, optionally processes them, and writes a chunk at a commit interval. Job/Step execution metadata distinguishes logical instances, attempts and restart state.

[S41] [S42]

Worked example · design exercise synthesis

An overnight reconciliation job handles rows in chunks. If a later chunk fails, previously committed chunks remain; restart behavior depends on metadata and the components’ restart contracts.

[S41] [S42]

Engineering decision synthesis

Choose chunk size against transaction duration, memory and write cost. Use stable job parameters and restartable input ordering; external side effects still need deliberate idempotency.

[S41] [S42]

Pitfall & diagnosis synthesis

A restarted job is not equivalent to replaying every row from zero. Changing input between attempts or losing execution metadata can break assumptions and duplicate effects.

[S41] [S42]

Improve & validate synthesis

Fail a run deliberately halfway through. Verify which chunks commit and which rows resume; measure processing rate, skip/retry counts and resource contention.

[S41] [S42]
Keep this: Restartability is a data contract, not a checkbox.
Check yourself: Does failure in chunk 8 undo chunks 1–7?

Normally no. Each completed chunk already committed within its own transaction boundary.

Sources & further reading

  1. [S41] Batch chunks

    Spring project maintainers · documentation · accessed 2026-10-09 · Documentation retrieved 2026-10-09

    Supports: Reader/processor/writer; Commit intervals

    Read the linked section to validate the mechanism and its version-specific constraints.

  2. [S42] Batch domain model

    Spring project maintainers · documentation · accessed 2026-10-09 · Documentation retrieved 2026-10-09

    Supports: JobInstance; JobExecution; StepExecution; Restart metadata

    Read the linked section to validate the mechanism and its version-specific constraints.