Menu

The replay that posted twice: idempotency keys are a contract, not a convenience
πŸ“°

The replay that posted twice: idempotency keys are a contract, not a convenience

DEV Community: apiΒ·InAppΒ·6 days ago
#Suau8XRR
#devtoapi#devto#dev#retry#webhook
Long article (262 words) β€” no AI summary yet.
Reading 0:00
15s threshold

I built a handler that listened to a webhook, parsed the payload, and created a record. During testing I retried a delivery manually and got a duplicate. Fine, I thought β€” I'll just dedupe on the event ID. Then a real retry happened 40 minutes later with a slightly different timestamp and my dedup silently missed it. The record was created twice and downstream billing picked up both.

The mistake was treating idempotency as a client-side courtesy. What actually matters is the key: a stable identifier the sender puts in an Idempotency-Key header, and the receiver stores against the resulting side effect. If the key is present and already seen, return the original response, do not re-execute. If it's missing, you have to either generate one from deterministic inputs or refuse the request.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.