Best Division

Spread Your Knowledge

  • All topics
  • About us
  • Contact us
  • Privacy policy
  • Terms of service
  • Copyright
  • Facebook
  • Twitter
  • Instagram
  • Youtube
  • LinkedIn
  • Pinterest
  • Github
  • Tumblr

© 2026 Best Division

How do you manage advanced fault recovery in Spring Batch?

Java
Jayant Kumar
Jayant Kumar@jayantkumar314
PublishedJan 3, 2025
UpdatedNov 16, 2026
6 min read

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.

Table of Contents

  • Classify failures before you configure anything
  • Configuring retry with backoff and skip limits
  • How chunk transactions limit the damage of a failure
  • Recording skipped items with listeners
  • Restarting failed jobs from the last commit
  • Keeping high-frequency jobs fast and safe
  • Frequently Asked Questions
    • What is the difference between retry and skip?
    • Why does my processor run more than once for the same item?
    • Can a failed job continue from where it stopped?
    • Do I still need @EnableBatchProcessing in Spring Boot 3?
  • Summary

Classify failures before you configure anything

Recovery rules should follow the kind of error, so classify first.

Error typeExamplesRight response
TransientNetwork timeout, deadlock, lock timeoutRetry with backoff
Bad dataMalformed line, validation failureSkip and record the item
SystemicDatabase down, disk fullFail the step and restart later

Retrying bad data wastes time, and skipping transient errors silently loses records. Use separate exception lists for each category.

Configuring retry with backoff and skip limits

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.

java

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.

How chunk transactions limit the damage of a failure

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:

  • Make processors and writers idempotent. Use upserts, natural keys, or a deduplication table, so a repeated item causes no duplicates.
  • Do not perform non-transactional side effects (sending an email, calling a payment API) inside a processor without protection. Move them to a later step, or record them in an outbox table written within the chunk transaction.

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.

Recording skipped items with listeners

Skipping silently is dangerous, so log every skipped item.

java

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.

Restarting failed jobs from the last commit

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:

  1. Use a durable relational database for the job repository in production, not the in-memory one.
  2. Keep identifying parameters stable (for example a business date) so a rerun targets the failed instance. Add a RunIdIncrementer only when you want new instances.
  3. Set allowStartIfComplete(false) (the default) so completed steps are not repeated.
  4. Detect jobs left in STARTED after a crash and mark them failed before restarting. A JobExplorer and JobOperator support this.

Keeping high-frequency jobs fast and safe

For jobs that run every few seconds or minutes:

  • Prevent overlapping runs of the same job, for example with a database lock or a unique business parameter.
  • Use partitioning or multi-threaded steps only when reader state is thread-safe. A multi-threaded step needs saveState(false) on most readers, which weakens restart, so prefer partitioning when you need both scale and restartability.
  • Expose Micrometer metrics (Spring Batch publishes timers and counters) and alert on job failure counts and step durations.
  • Clean up old job metadata on a schedule, because the repository tables grow quickly with frequent jobs.

Frequently Asked Questions

What is the difference between retry and skip?

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.

Why does my processor run more than once for the same item?

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.

Can a failed job continue from where it stopped?

Yes. Rerun it with the same identifying parameters. A restartable reader and a persistent job repository let it resume from the last committed chunk.

Do I still need @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.

Summary

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.

Share