Spring Batch: chunk commits and safe restarts
Prerequisites: 01-ecosystem
What survives a batch failure?
Which work remains after a failed chunk?
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]Check yourself: Does failure in chunk 8 undo chunks 1–7?
Normally no. Each completed chunk already committed within its own transaction boundary.