How to know the replica count of a Spring Boot application in Kubernetes

8/16/2020

I have a Spring Boot 2.2.x backend deployed in kubernetes. I want to split a workload in this backend by the number of replicas of this application. If I have one instance, the range of data (which comes from an external API) must not be split at all. If I have two instances, the first replica must work on the first half of the data and the second replica must work on the other half, and so on.

What is the better way of manage this kind of issue ? Is there a spring library available to dynamically detect the number of instances and partition the data ? I already have a redis avaiblable, I think I can store some useful information in it.

Thanks for you thoughts.

-- Olivier
kubernetes
partitioning
spring
spring-boot

1 Answer

8/16/2020

You can use spring batch remote chunking pattern to split across multiple processes(each one of the process is a replica pod), communicating with each other through some middleware. Spring batch supports redis as middleware

remote chunking

-- Arghya Sadhu
Source: StackOverflow