Advanced fault recovery in Spring Batch combines four things: skip and retry policies for bad items and transient errors, chunk-level transactions so a failure rolls back only the current chunk, a persistent JobRepository so a failed job restarts from its last commit, and monitoring through listeners and metrics. For high-frequency jobs, keep chunks small, make writers idempotent, and run steps in parallel only where restart state stays consistent.
This guide uses Spring Batch 5 with Spring Boot 3 (Java 17 or later). In that version JobBuilderFactory and StepBuilderFactory are removed. You build jobs with JobBuilder and StepBuilder, passing in the JobRepository and a PlatformTransactionManager.
Recovery rules should follow the kind of error, so classify first.
| Error type | Examples | Right response |
|---|---|---|
| Transient | Network timeout, deadlock, lock timeout | Retry with backoff |
| Bad data | Malformed line, validation failure | Skip and record the item |
| Systemic | Database down, disk full | Fail the step and restart later |
Retrying bad data wastes time, and skipping transient errors silently loses records. Use separate exception lists for each category.
A fault-tolerant step is created with faultTolerant(). The following Spring Batch 5 step retries transient database errors three times with exponential backoff, and skips up to ten unparseable items.
retryLimit counts attempts of the same item or chunk. skipLimit is the total number of skipped items allowed in the step. Exceeding it fails the step. The spring-retry library supplies the backoff policy and is a dependency of Spring Batch 5. Newer Spring Batch versions are moving to the retry support in Spring Framework core, so check the release notes for your version before upgrading.
Each chunk of 100 items is read, processed and written in one transaction. If the writer throws, the transaction rolls back and the chunk is retried or its items are scanned one by one to find the bad one. On a failure in a fault-tolerant step, Spring Batch re-processes items individually after the rollback, which means processors can run more than once for the same item.
Two consequences matter for high-frequency work:
Smaller chunks reduce the work lost on a rollback and the cost of scanning, but they add commit overhead. Measure with realistic data. Values between 50 and 1,000 are common starting points.
Skipping silently is dangerous, so log every skipped item.
Register it with .listener(eventSkipListener) on the step builder. Writing skipped items to a dead-letter table lets operators fix and reprocess them without re-running the whole job.
Spring Batch stores step execution state, including the read count and each ExecutionContext, in the job repository tables. When a job instance fails, launching it again with the same identifying parameters resumes the failed step from the last committed chunk, provided the reader is restartable (for example JdbcPagingItemReader, FlatFileItemReader and JpaPagingItemReader save their position). Readers marked saveState(false) start over.
Useful rules for restart:
RunIdIncrementer only when you want new instances.allowStartIfComplete(false) (the default) so completed steps are not repeated.STARTED after a crash and mark them failed before restarting. A JobExplorer and JobOperator support this.For jobs that run every few seconds or minutes:
saveState(false) on most readers, which weakens restart, so prefer partitioning when you need both scale and restartability.Retry runs the same item again, usually for transient errors. Skip gives up on an item and continues with the rest of the step, within skipLimit.
After a rollback in a fault-tolerant step, Spring Batch reprocesses the chunk item by item. Processors should therefore have no side effects, or be idempotent.
Yes. Rerun it with the same identifying parameters. A restartable reader and a persistent job repository let it resume from the last committed chunk.
@EnableBatchProcessing in Spring Boot 3?Not usually. Spring Boot auto-configures Spring Batch, and adding @EnableBatchProcessing turns off parts of that auto-configuration, so add it only when you want to define the infrastructure beans yourself.
Classify errors as transient, bad data or systemic, and apply retry, skip and fail accordingly. Rely on chunk transactions and a persistent job repository for restartability, make writers idempotent, and record skipped items in a dead-letter store. For high-frequency jobs, prevent overlap, monitor with metrics, and prune old metadata.