What are correct system designs to prevent multiple pods from handling same domain event?

3/27/2020

What are correct system designs to prevent multiple pods from handling same domain event ? If I have a service that spawns multiple instances on Kubernetes k8s. And all of them subscribe to same domain event. What are strategies to prevent same event handler being executed multiple times ? On each pod ?

Lets consider this example:

  1. we have two services A and B
  2. there is one instance of A running and two of B
  3. A dispatches the event that B subscribes to
  4. both instances of B run event handler for it

Now we don't want to run same handler on each instance for it. But because its a pub/sub all subscribers get notified of an event.

Also in case there would be third service C that subscribes to the same even, we want him to handle it as well.

So the issue is if we run multiple instances of the same handler. Only first should handle it. What would be correct system architecture to deal with it ?

-- vardius
concurrency
domain-driven-design
event-handling
kubernetes

0 Answers