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

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.



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1