The world is moving very fast with the existence of technology. Enterprises and Corporations want to perform tasks faster and more accurately. The processing of such data includes daily report generation, processing bulk data without human intervention. Spring batch is the solution to most of these tasks. It enables processing of bulk data in a transactional manner and performs day to day activity with precision and speed.
- Spring batch is based on spring framework and is very lightweight. The core concept of spring batch as the name suggests is processing of data in batches.
- It is based on OOPS concepts and uses POJO based development.
- Spring Batch provides advance services and features for high volume and high performance batch jobs using optimization and partitioning techniques. It is highly scalable and can be used for processing of high amount of data.
- It is not a scheduler and should be used in conjunction with a scheduler.
Why do we need Spring Batch?
Let us go back into the history for looking into the need for spring batch.
While open source software projects and open source communities have majorly focused on web-based and messaging-based architecture frameworks, the reusable architecture frameworks took a back seat to accommodate Java-based batch processing needs, considering the continuous need to handle such processing on a daily basis within the enterprise.
The lack of a standard, scalable and reusable batch architecture resulted in the development of many in-house solutions from various companies.
SpringSource and Accenture collaborated to create something more standard and reusable. Having the proven technical experience in implementing batch architectures, SpringSource’s depth of technical experience and spring’s proven programming model together made a powerful architecture to create high-quality, market-relevant software aimed at filling an important gap in enterprise Java.
Accenture contributed with previous proprietary batch processing architecture frameworks to the Spring Batch project along with support team, enhancements, and the future roadmap.
Spring Batch Usage
A batch program reads a large number of records from a database, file, or queue, processes the data based on the business needs, and then writes back data in the desired form.
Spring Batch automates this basic batch iteration, providing the capability to process similar transactions as a set, all this can be done in an offline environment without any user interaction.
Batch jobs are part of most IT projects and Spring Batch is the only open source framework that provides a robust, enterprise solution.
Let us look at some of the real-time usages of spring batch both business wise and technical.
Spring Batch Business Use Case
- At the end of a month when a company has to send salary to its employee’s respective accounts.
- Processing of salary slips at month end is when spring batch can be used.
- Sending out mass communication emails.
- For generating automated reports on daily, weekly or monthly basis.
- Executing business workflow automatically without human intervention.
Spring Batch Technical Use Cases
- For automatic test execution at a defined frequency.
- This can be used for doing automatic database updates on a predefined frequency.
- It can be used with a queue system to handle huge amount of transactions without any failure.
- Spring batch can be used along with APIs to perform tasks such as health check for server or application, dummy data generation for load test, etc.
Spring Batch Architecture
The diagram below shows the technical architecture of Spring Batch.
- Application: This contains all the batch jobs and code written by the developer based on business needs.
- Batch Core: It contains the runtime classes necessary to run a batch job. The classes such are JobLauncher, Job and Step implementation are part of the Batch Core.
- Batch Infrastructure: This contains the reader and writer services which are used by developer and the framework itself. The classes are
ItemWriter. It also contains services to retry read and write.
Spring Batch Processing
A regular spring batch processing workflow is shown below.
- In the workflow shown, the data is read from database using reader which is part of the Spring Batch.
- Then the data is passed to processor for processing the data based on the business requirement.
- The processed data which is now modified data is passed to the writer, which writes the data back into the database.
- The source of data can be Database, file, queue etc.
Spring Batch Advantages
Let’s see the advantages of using Spring Batch processing.
- Developers can concentrate on implementation of business logic and framework will take care of the iterations.
- Since it is a layered architecture the decoupling between different layers is easy.
- You can implement a core business logic that can be used as generic implementation throughout the application.
- It provides separation between infrastructure and application at the JAR level as well resulting in easy and scalable deployment.
That’s all for a quick introduction of Spring Batch.
Reference: Project Official Page