Spring Batch vs Spring Integration — When to Use Each
Fast recall
Quick revision
Core answer
Architectural understanding of when batch processing is appropriate versus event-driven integration, and awareness that both frameworks coexist in the Spring ecosystem
Thinking Spring Integration can replace Spring Batch for bulk data processing — it lacks chunk transactions, job restart, skip/retry policies, and the execution metadata model
Describe the canonical integration pattern — Spring Integration polls a directory or message queue and launches a Spring Batch job via `JobLaunchingGateway` when files arrive
Interview-ready guide
Interview answer
Spring Batch and Spring Integration solve fundamentally different problems but are frequently combined.
Spring Batch — structured bulk processing:
- Designed for: processing millions of records from a file or database on a schedule
- Key features:
JobRepositoryfor state persistence, restart from failure, skip/retry policies, partitioned parallel processing, chunk-level transaction management - Use when: defined start, defined end, need to track how many records were processed, skipped, committed
Spring Integration — event-driven message routing:
- Designed for: connecting systems and routing messages in real time
- Key features: message channels, adapters (file system, JMS, AMQP, SFTP, email), transformers, routers, filters
- No concept of job state, checkpointing, or restart — continuous pipeline
The canonical hybrid pattern:
- Spring Integration watches an S3 bucket or SFTP folder for new files
- When a file arrives, Integration launches a Spring Batch job with the file path as a
JobParameter - Spring Batch reads, processes, and writes the file's records with full fault tolerance
- Integration handles the event-driven trigger; Batch handles the heavy data processing
Decision rule:
- Bounded dataset, needs restart/skip/retry — Spring Batch
- Continuous event stream, system integration, message routing — Spring Integration
- Both, with Batch triggered by Integration events — standard enterprise pattern
Common pitfalls:
- Using Integration for bulk processing because it 'feels lighter' — works at small scale, breaks when you need restart
- Using Batch for real-time events because the team already knows it — chunk commits add latency
- Not using
RunIdIncrementerwhen launching Batch from Integration — restart semantics get confusing
In an interview I'd emphasize that the question is rarely 'which one' — it's usually 'how do they fit together'.
Spring Batch vs Spring Integration — When to Use Each
Direct Answer
Spring Batch is designed for scheduled, finite, high-volume data processing — bounded datasets with start/end semantics, restart capability, and transactional chunk processing. Spring Integration is designed for event-driven, continuous, message-based integration workflows that connect heterogeneous systems via channels, transformers, and adapters. They are complementary, not competing — Spring Integration can trigger and orchestrate Spring Batch jobs (file arrival → launch job), and Spring Batch can use Spring Integration channels as item sources or sinks for remote partitioning.
Common Mistakes & Pitfalls
Thinking Spring Integration can replace Spring Batch for bulk data processing — it lacks chunk transactions, job restart, skip/retry policies, and the execution metadata model
Check your understanding
Answer these without looking back at the article.
- How would you design a system where new files arriving on SFTP automatically trigger a Spring Batch job?
- Could you use Spring Integration's error handling channels as a replacement for Spring Batch's skip/retry logic?
- When would you choose Apache Camel over Spring Integration for system integration alongside Spring Batch?
- How does `JobLaunchingGateway` interact with `JobInstance` uniqueness when launching from a polling adapter?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.