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 handle fault recovery workflows in Spring Batch?

Java
Jayant Kumar
Jayant Kumar@jayantkumar314
PublishedJan 2, 2025
UpdatedNov 16, 2026
9 min read

Handle fault recovery in a low-frequency Spring Batch job with three layers: make each step fault tolerant (retry transient errors, skip bad records), persist progress in the JobRepository so a failed run can restart from the last committed chunk, and alert on failure so a human or a scheduler acts quickly. Because the job runs only daily, weekly or monthly, a failure that nobody notices can cost a whole cycle, so detection and restart matter as much as the retry logic.

The examples target Spring Batch 5 with Spring Boot 3, where JobBuilderFactory and StepBuilderFactory no longer exist and builders take the JobRepository and a PlatformTransactionManager directly.

Table of Contents

  • Why low-frequency jobs need explicit recovery design
  • Making a chunk step fault tolerant
    • Adding a back-off between retries
  • Recording skipped records with a SkipListener
  • Restarting a failed job from the last committed chunk
  • Detecting failures and alerting
  • Design rules that make recovery safe
  • Frequently Asked Questions
    • What is the difference between retry and skip in Spring Batch?
    • Can I restart a Spring Batch job after the application crashed?
    • Why does my restarted job start from the beginning?
    • How many skips are too many?
  • Summary

Why low-frequency jobs need explicit recovery design

A job that runs every few seconds can simply be run again. A monthly billing export cannot: it processes a large data set, the input changes between runs, and a partial run may already have written output. Three failure types need different handling:

Failure typeExampleRight response
TransientDatabase deadlock, network timeoutRetry the item or chunk with a back-off
Bad dataMalformed CSV line, constraint violationSkip the record and log it for review
SystemicTarget database down, disk fullFail the step, keep state, restart later

Spring Batch stores the status of every job and step execution, including read and write counts and the ExecutionContext, in the BATCH_* tables. That state is what makes a restart "intelligent": the next run knows what already committed.

Making a chunk step fault tolerant

Call faultTolerant() on a chunk-oriented step builder, then declare which exceptions to retry and which to skip.

java

In Spring Batch 5 with Spring Boot 3 the infrastructure is auto-configured, so you do not need @EnableBatchProcessing unless you want to take over the configuration yourself.

Things to know about this configuration:

  • retryLimit(3) counts attempts for the same item or chunk, so a transient error is retried before it counts against skipLimit.
  • skipLimit(50) is a safety valve. When more than 50 records are skipped the step fails, which is what you want when a whole input file is corrupt.
  • If a processor or writer throws a skippable exception, Spring Batch rolls back the chunk and re-processes the items one at a time to find the bad one. Keep processors free of side effects so this re-run is safe.

Adding a back-off between retries

Retrying immediately rarely helps with a database that is briefly overloaded. Add a back-off policy so each attempt waits longer.

java

Retry support in Spring Batch 5 comes from the Spring Retry library, which is a dependency of spring-batch-core. Check the documentation of the Spring Batch version you use before upgrading across major versions, because retry support is evolving.

Recording skipped records with a SkipListener

Skipping silently loses data. Implement SkipListener so every skipped item is written somewhere a person can review it.

java

For production, write skipped items to a dead-letter table or file instead of only the log, so the business owner can fix and resubmit them before the next cycle.

Restarting a failed job from the last committed chunk

Every step that reads through a stateful ItemReader (such as FlatFileItemReader or JdbcCursorItemReader) saves its position in the ExecutionContext at each chunk commit. When the job fails, its JobExecution is marked FAILED. Launching the same job with the same identifying parameters creates a new execution of the same JobInstance, and the failed step resumes after the last committed chunk. Completed steps are not run again.

java

Rules that decide whether a restart works:

  1. The identifying job parameters must be identical. Use a business key such as the reporting period, not a timestamp.
  2. A COMPLETED job instance cannot be launched again with the same parameters.
  3. A step can opt out of the "do not repeat completed steps" behaviour with allowStartIfComplete(true), and startLimit(n) caps how many times a step may be started.
  4. Custom readers and writers must implement ItemStream and save their state in update(), or restart will begin from the start of the input.

You can also restart by execution id through the JobOperator interface, which is convenient from an admin endpoint or a support script.

Detecting failures and alerting

Low-frequency jobs need a signal that fails loudly. A JobExecutionListener runs after the job ends, whatever the outcome.

java

Register it with .listener(failureAlertListener) on the JobBuilder. Also alert on the absence of a run: a scheduler that silently stops is a failure no listener can see. Many teams add a monitor that checks the newest BATCH_JOB_EXECUTION row against the expected schedule.

Spring Boot runs all jobs at startup by default. For scheduled or externally triggered jobs, set spring.batch.job.enabled=false and launch them explicitly.

Design rules that make recovery safe

  • Make writers idempotent, for example with an upsert keyed by a business id, so a re-run chunk does not create duplicates.
  • Keep chunk sizes moderate. A smaller chunk loses less work on failure but commits more often.
  • Never put a timestamp in identifying parameters if you want restart to work.
  • Test failure paths with JobLauncherTestUtils and a reader that throws on a chosen item.
  • Keep the BATCH_* tables in a durable database, not the in-memory default of a test setup.

Frequently Asked Questions

What is the difference between retry and skip in Spring Batch?

Retry runs the same operation again, which is useful for transient errors. Skip gives up on one item and continues with the rest, which is useful for bad data. They combine: an item is retried up to the retry limit, and if it still fails and the exception is skippable, it is skipped.

Can I restart a Spring Batch job after the application crashed?

Yes, as long as the metadata tables are in a persistent database. A crashed execution may stay in STARTED status, so mark it FAILED or STOPPED (for example through JobOperator or a recovery routine) before restarting the same instance.

Why does my restarted job start from the beginning?

Usually the reader does not save its state, the job parameters changed so a new job instance was created, or the step is configured with allowStartIfComplete(true). Check the BATCH_JOB_INSTANCE table to see whether a new instance was created.

How many skips are too many?

Choose a limit that reflects normal data quality for your feed. If skipped records exceed that limit, the input is probably broken and failing the step is safer than producing a partial result.

Summary

Combine fault-tolerant steps (retry with back-off for transient errors, a bounded skip for bad records), a persistent JobRepository with stable identifying parameters for restart, listeners that record skips and raise alerts, and idempotent writers. Together they let a monthly or weekly Spring Batch job recover from most failures without rerunning the whole data set.

Share