Skip to content

.tip

· one of the small things

Webhooks arrive twice, so store the event id

Providers retry when your endpoint is slow, and a retry is the same event all over again. The usual result is charging a customer twice.

INSERT INTO webhook_events (id) VALUES ($1) ON CONFLICT DO NOTHING RETURNING id;
-- no row returned: already processed, respond 200 and stop

Insert the event id first, in the same transaction as the work. Answer 200 quickly and do the slow part from a queue.

securitydistributed-systems