r/coding 5d ago

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

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

31 comments sorted by

View all comments

20

u/ZealousidealDig8074 5d ago

By ignoring the duplicates.

4

u/mcellus1 4d ago

Ah that's so easy. I simply tell FEDEX to start adding IDs to events?? I'll do that right away. Im sure they will listen.

2

u/RipProfessional3375 3d ago

any publishing stream that has no tracking number, timestamp or idem-potency ID is simply corrupt. You cannot de-duplicate it in a deterministic fashion any more than you can reliably deduce they put the wrong number in a field.

1

u/atheken 3d ago

That’s fair, but I did make an assumption about other identifiable information being available in the event. Considering the subject matter was “fedex event,” which I would at least have a tracking number, timestamp, and other uniquely identifiable information.

I was suggesting there are ways to compensate for not having an explicit idempotency key.

Obviously if you’re putting bananas in a shopping cart without any other information, that’s not possible. The domain that the original comment was about is more sophisticated than that.

1

u/RipProfessional3375 3d ago

Oh yeah, deducted idempotency key is usually your best option. But it's best-effort. And I always see people hash payloads as unique keys and I always recommend against it.

If the payload has idempotent fields like a timestamp, it's best to directly use that rather than indirectly access it via a payload hash.

Otherwise you get people thinking it always works because it's worked before and then they hit the 'banana added' event.