Ads

Architecture of Spring Batch - A Comprehensive Overview


Spring Batch follows a layered architecture that promotes modularity, separation of concerns, and reusability. The key components of the Spring Batch architecture are as follows:

A] Application Components

B] Batch Core (Item Readers, Item Processors, and Item Writers)

C] Infrastructure Components

The below diagram shows the layered architecture of the spring batch which supports the ease of use and extensibility for end-user developers.


Figure 1. Spring Batch - Layered Architecture

 Application Components:-

These are the custom components developed by the application developer, responsible for defining the batch processing logic, data processing, and business rules. They are further divided into two primary components:

A. Job -

A job represents a specific batch process, consisting of one or more steps that need to be executed sequentially or in parallel. Each job is composed of multiple steps, and each step performs a specific task during batch processing.

B. Step

A step represents an individual unit of work within a job. It encapsulates the processing logic and can perform operations like reading, processing, and writing data.

 Batch Core:-

The item reader, item processor, and item writer are the core processing components responsible for reading data, applying business logic, and writing the processed data. They are pluggable components, meaning developers can customize them according to the specific requirements of their batch jobs.

A. ItemReader

Reads data from a data source, such as a database, a CSV file, or a message queue, and provides data to the processor for further processing.

B. ItemProcessor

Processes the input data from the ItemReader and applies business logic, filtering, transformation, or enrichment to the data before passing it to the ItemWriter.

C. ItemWriter

Writes the processed data to the desired output destination, such as a database, a file, or a message queue.

 Infrastructure Components:-

These are the core components provided by Spring Batch, which handles the orchestration and execution of batch processing jobs. They include:

A. JobLauncher

Responsible for launching job instances and coordinating the execution of steps within a job.

B. JobRepository

Manages the metadata associated with job instances, steps, and their execution status. It also allows for restart ability and recovery of failed jobs.

C. JobExplorer - 

Enables inspection of job metadata, such as job and step execution details, making it helpful for monitoring and reporting.

D. JobOperator - 

Provides programmatic control over job execution, allowing starting, stopping, and restarting jobs from external systems.

 Spring Batch Execution Flow:-

The execution flow of a Spring Batch job can be summarized as follows:

A. Job Launch

The JobLauncher receives a request to launch a job instance and starts the execution process.

B. Step Execution

The JobLauncher starts executing the steps of the job sequentially or in parallel, depending on the configuration.

C. Step Processing - 

For each step, the ItemReader reads data from the data source, passes it to the ItemProcessor for transformation, and then the processed data is sent to the ItemWriter for storage in the target destination.

D. Chunk-Oriented Processing - 

Spring Batch uses chunk-oriented processing, which processes data in configurable chunks, reducing the overhead of reading and writing data individually.

E. Step Completion - 

Once all the chunks are processed, the step is considered complete, and the JobLauncher moves on to the next step in the job.

F. Job Completion - 

After all the steps are executed successfully, the job is considered complete. However, if any step fails, Spring Batch allows for the restart ability of failed steps to resume processing from the last successful checkpoint.

Farhankhan Soudagar

Hi, This is Farhan. I am a skilled and passionate Full-Stack Java Developer with a moderate understanding of both front-end and back-end technologies. This website was created and authored by myself to make it simple for students to study computer science-related technologies.

Please do not enter any spam link in the comment box.

Post a Comment (0)
Previous Post Next Post

Ads before posts

Ads

Ads after posts

Ads
Ads