Engineering
A webhook reliability playbook for payments and fulfillment
A practical state-machine approach to duplicate events, delayed delivery, retries, and replaying failed operational webhooks without double charges or duplicate emails.
7 min read · Published 2026-11-25
Verify and persist before acting
Read the raw request body, verify the provider signature against that exact body, check the timestamp tolerance, and persist the provider event ID before starting side effects. Reject expired or malformed events without revealing signature details.
Use the provider event ID as an idempotency key. A second delivery of the same event should return success while leaving the fulfillment state unchanged. Do not use the customer email address, amount, or a generated request ID as the only key; none of those uniquely identifies an event.
Model fulfillment as a state machine
A useful payment workflow has explicit states such as pending, payment-confirmed, processing, delivered, and failed. Each transition should have narrow preconditions, an owner, and a timestamp. A short-lived lock or compare-and-swap operation prevents two concurrent requests from generating or emailing the same report.
Keep provider verification separate from artifact generation and email delivery. If payment is valid but email fails, the order remains paid and deliverable; it must not return to an unpaid state or trigger a second payment check later.
Make recovery an operator feature
Exhausted retries should move into a dead-letter view that shows the event type, reference, failure category, attempt count, and safe replay action. Redact payment credentials and customer content that is not needed for diagnosis.
Replay must be idempotent. Before adding a new retry mechanism, test the case where the provider already delivered the event, the previous worker completed the side effect but failed to record success, and two workers process the same event at once.
Monitor freshness, not only HTTP failures
A webhook endpoint can return 200 while the downstream queue stops moving. Alert on processing latency, oldest pending event age, failed-delivery rate, and dead-letter growth. Also monitor the expected volume of payment and fulfillment events so a silent disconnect is visible.
Record a correlation ID through verification, state transitions, PDF generation, email submission, and admin replay. The goal is not exhaustive logging; it is enough evidence to identify the exact transition that failed without copying sensitive customer content into logs.
This guide is educational and does not guarantee a business, security, or compliance outcome. Workflows and legal obligations must be assessed for your own systems and jurisdiction.
Keep reading