I have two instances of a spring boot microservice (Microservice A) and a load balancer. The Spring boot application is running in AWS Fargate with 2 desired tasks (2 instances of Microservice A).
If I request the microservice A the load balancer leads me at the first request to microservice A instance 1. The next request will be load balanced to microservice A instance 2. This is alternating on every future request.
On microservice A I have a Spring Service that has a List<String>
attribute. On every request I put something in this List.
The List is hold in memory, I dont want to put this List into a database.
In my case every further request fills the list on microservice A instance 1 and microservice A instance 2 alternating. But I want to fill only one List with every future request so my List input is not spreaded across my microservice instances.
So my question is:
Is there any way to share one List between these two microservice instances?
Do I have to establish some kind of communication between them or is there a better solution for this? Or do I have to configure my load balancer? A solution would be storing it in a database. But this would produce many DB calls and I want to prevent this because the purpose of the code is to prevent DB calls.