A customer pays for an order, but the payment event reaches your app while the database is briefly unavailable. The provider retries, then the app processes the same event twice and creates two fulfilment jobs. The opposite failure is also possible: the endpoint returns success before saving the event, and the order never moves forward. A webhook is a delivery mechanism, not a complete order-processing system.
Razorpay's webhook best practices describe retries, duplicate events, event IDs and possible out-of-order delivery. Your application has to handle those conditions deliberately.
Separate receipt from business processing
First verify the provider's signature using the raw request body according to its documentation. Reject invalid events. For a valid event, store the provider event ID, event type, payload or a safe reference, received time and processing status in a durable inbox. The event ID should be unique within that provider account. Only acknowledge successful receipt once that write has succeeded.
Do the slow work—creating an order fulfilment task, sending email or updating analytics—in a worker. That reduces the chance that an otherwise valid delivery times out while the app waits for several downstream services. If the inbox database is unavailable, return an error so the provider can retry; do not return success and hope a background process will remember an event that was never saved.
Deduplicate delivery and the business action
If the same event ID arrives again, the inbox insert should recognise it and avoid another processing job. But event deduplication alone is insufficient: two different events may refer to the same payment or order transition. The fulfilment operation should have its own invariant, such as “create at most one fulfilment record for this paid order”. Enforce that with a database constraint or transactional state change, not only an in-memory check.
Do not assume events arrive in the order they happened. Read the current entity state or retrieve it from the provider when an event would move an order backward. For example, a late “payment authorised” notification should not undo an already recorded captured payment. Keep the actual event history for diagnosis.
Retry failures without looping forever
Classify failures. A temporary database timeout or a rate limit can be retried with increasing delay. A malformed internal mapping or unknown product ID needs investigation. After a bounded number of attempts, move the event to a review queue with the error, attempt count and last tried time. This queue should be monitored; a dead-letter table nobody checks is only delayed data loss.
Provide a controlled replay action after the underlying issue is fixed. Reprocessing must use the same idempotent business logic and preserve the original event ID. Do not replay a raw payload into production from a public admin link without authentication, audit logging and access control.
Reconcile orders independently
For business-critical payments, periodically compare app orders with the payment provider's authoritative records. The provider may stop retrying after its configured window, and staff may miss an alert. A reconciliation job detects a paid order that still says “pending” in your app, then routes it to review. Stripe's webhook troubleshooting guidance shows how delivery failures appear in its dashboard; your own inbox and order state are still needed to explain whether fulfilment completed.
Test four cases before launch: duplicate delivery, out-of-order events, a database outage before inbox write and a worker failure after successful receipt. For each case, verify that the customer gets one correct outcome and that an operator can find the event afterward.
My SaaS payment reconciliation guide covers the later settlement check. If your product has paid orders stuck in “pending” or duplicate fulfilment, show me a redacted event flow and I can help design the inbox, worker and recovery path.
Reliable webhooks are built around durable records and safe repetition, not optimistic one-shot callbacks.





