Microservices - approaches to multiple container instance -> single event consumption
I would like to ask your opinion on a microservice use-case, and what would be the best approach to tackle it.
Let's say you have 10 microservices, each one implementing a given bounded-context, as per DDD.
Each microservice is constantly publishing its own events so that the others who subscribe to this consume them. So far, so good... pretty standard stuff.
Let's also assume that we have some microservices that generate and consume a lot of events and are also strongly involved in synchronous API calls (REST-based).
Because the load on these microservices is not uniform throughout the day, they start running on 1 container instance at the beginning of the day, scales to 4 or 5 container instances by midday, and scale back to 1 and around 7 PM.
The underlying data layer for this microservice is a single DB instance serving all container instances.
Each instance of these microservices that is spawned subscribes to a set of topics that the other microservices will publish.
However, we want that any given event that microservice A subscribes is only processed one time by one of its pool of container instances. So, if microservice A is running 4 container instances and Event X is subscribed to, each Event X is to be processed by just one of the instances, not all 4.
Possible solutions that we believe may address this:
- Use Direct-To-One (DTO)?
- Use Topic-To-Queue mapping?
What other possibilities are out there?