I’m trying to implement microservices and I’m still super new to the subject, but, I was able to answer most of questions.
However, one of the questions that I can’t come up with a good solution to is how do I make my consumer idempotent when my publisher publishes at least once?
What happens without making Consumer idempotent:
Our consumer receives
Event A multiple times, and
Event A is asking to pay X dollar to
User A, without handling this correctly, we’ve paid
User A 3 * X times.
What I’ve come up with is this solution:
We create an
Events table in
Service A (publisher), we create an entity with an
serviceName (in this case
Events table, then we proceed to publish the event.
Service B (consumer), we create a
ReceivedEvents table, which holds both
serviceName as primary key, this way, whenever we have a new event, we will first check if the event is inside
ReceivedEvents, if not, we proceed to complete the task.
Is this approach good enough? Is there an alternative to this approach?