Every webhook provider retries. If your endpoint is slow, or the provider can't tell whether you got it, the same payload comes again. Sometimes a minute later, sometimes in the same second.
You can add duplicates yourself, too. I once built a relay that saved each webhook to storage before forwarding it to the app, so nothing was lost while the app was down. It worked. It also meant that if a forward timed out after the app had already saved the webhook, the relay sent it again later.
So the job isn't to stop duplicates. It's to make the second arrival boring:
- Key on the provider's ID. WhatsApp gives every message an ID. A unique index on it means the second copy finds the first row instead of creating a new one.
- Make state move one way. A delivery status can only go forward: sent, delivered, read. A repeat or a late arrival can't undo anything.
- Lock the side effects. Saving a message twice is harmless if the second save is a no-op. Replying to it twice isn't, so the bot takes a lock per customer.
- Keep a record of every arrival. When someone asks why a message looks odd, a log of every webhook that touched it answers the question in a minute.
Assume twice, and once takes care of itself.