Handle webhooks that arrive twice, out of order, or during an outage — verify, persist, deduplicate on the provider's event id, then process. Use when consuming Stripe, GitHub, or any provider webhook.
--- name: write-an-idempotent-webhook-handler category: coding description: >- Handle webhooks that arrive twice, out of order, or during an outage — verify, persist, deduplicate on the provider's event id, then process. Use when consuming Stripe, GitHub, or any provider webhook. --- # Write an Idempotent Webhook Handler Every webhook provider guarantees *at least once* delivery. None guarantee exactly once, and none guarantee order. So the handler you actually need must survive the same event arriving three times, arriving out of sequence, and arriving while your database is down. Treating a webhook like a normal request is how people end up double-charging customers. ## The shape that works Five steps, in this order. The order is the design. ``` 1. verify signature reject before parsing 2. persist raw event store it, unprocessed 3. return 200 immediately 4. deduplicate on event id exit early if already handled 5. process in a worker, retryable ```
You are reading the opening of this skill.
The rest is open to any signed-in account — free included. Reading the library costs nothing.
Shared publicly by the author and open for any use. See the Terms.