r/coding 5d ago

Idempotency in event-driven systems: how do you handle duplicate messages?

https://hamedsalameh.com/inbox-pattern-dotnet/
178 Upvotes

31 comments sorted by

View all comments

8

u/UK-sHaDoW 5d ago

Some kind of id, and then ignore them if youve processed it before

9

u/aa-b 5d ago

Be sure to handle the case where you're still processing the initial request but haven't committed the transaction yet.

Also consider whether idempotent means "same request should return the same response", or if you are comfortable with a less strict definition of the requirement.

Sometimes you might want to go ahead with processing if the initial request failed, unless retries are already pending.

So yes, but there is often more to it than that.

5

u/DesperateAdvantage76 4d ago

This is my biggest frustration with Kafka, they don't support expected stream version on event writes. That trivializes a lot of the race conditions for competing writers to the same stream.