Designing idempotent payment webhooks that survive retries
Processors retry. Banks duplicate files. Your handlers must not double-pay or double-post — patterns that work in production.
Webhooks are at-least-once delivery systems pretending to be events. Engineer for duplicates by default.
Store external IDs with unique constraints and return 200 on replays when state already matches intent. Log mismatches loudly.
Separate ingestion from side effects. Queue ledger commands only after durable dedupe.
Chaos-test with intentional duplicate bursts before Black Friday payroll week.
