kubernetesspring-batch

Spring Batch and multi-instance Kubernetes application with a single database


I do not completely understand if Spring Batch works fine in a Kubernetes environment with multiple instances. From this question I understand that in general it works fine, but in the answer it is not mentioned that it works fine in a multi-instance deployment using one database.

Our setup looks like this: We have multiple instances of the application running in Kubernetes and they sharing the same database instance. Some jobs would be triggered by user interaction (in one of the many pods that are answering the request from the UI) and some are triggerd by a cronjob in Kubernetes (e.g. data reorg) (in one of the many pods that are answering the REST request from the cronjob). All pods are containing the identical application.

Does this setup work fine with Spring Batch?

thanks for your help :-)


Solution

  • As far as Spring Batch is concerned, all these things are deployment details. It is up to you to design your jobs and job instances with that in mind. This is what I explained in details in the Choosing the right Spring Batch job parameters and Choosing the Right Kubernetes Job Deployment Pattern sections. Note that this blog post is linked in the answer you shared.

    What Spring Batch guarantees, thanks to the centralized job repository design (which is what you are referring to as "ONE database"), is preventing duplicate and concurrent job executions of the same job instance.

    So the answer to your question is yes, as long as you choose the right deployment pattern for your Spring Batch jobs and Kubernetes jobs.