Engineering notes
Payment Webhooks: Handle Duplicates and Late Events
Keep payment events from creating duplicate orders. A practical design for signature checks, durable inboxes, retries and visible exceptions.
A customer pays, closes the browser and contacts support because the order still says pending. Meanwhile, the payment provider has sent the same notification twice. The integration needs an explicit processing contract, not a larger timeout. This hypothetical checkout scenario separates delivery, business processing and the customer-facing order state.
The browser return is a useful hint
A success URL is a customer interface, not proof that money has settled. Customers can close tabs, lose connectivity or revisit a bookmarked return address. Use the provider's documented verification mechanism and identifiers to establish payment status on the server. Keep the order pending until the required evidence exists.
Show a useful pending screen with an order reference and a safe way to check again. Do not ask the customer to pay twice because a callback is slow. Model authorization, capture, refund and cancellation separately when the provider exposes them; a single paid boolean cannot explain all of these commitments.
Generated editorial illustration; not a record of a live system.
Accept delivery only after durable receipt
Verify the webhook using the provider's documented signature procedure, including its requirements for the raw request body. Reject invalid messages before using their content. Persist the event identifier, source, receipt time and processing state in a durable inbox before acknowledging successful receipt. If persistence fails, do not claim the event has been accepted.
Do the expensive work asynchronously. An inbox row lets a worker resume after a restart and gives support a reference that survives beyond one log line. Store only the payload fields the workflow needs and set a retention policy for sensitive payment details. Delivery success and business success should be distinct states in the monitoring view.
Deduplicate both the message and its effect
A unique provider-event identifier prevents the same delivery from creating several inbox entries. It may not prevent two different events about the same payment from attempting the same business action. Add a domain-level boundary, such as a unique payment-to-order association, and update the order inside a transaction that checks its current state.
Treat retries as normal. A notification can arrive after the local write succeeded but before the sender received its acknowledgement. Reprocessing should discover the existing result and stop safely. Do not deduplicate on amount and timestamp: two legitimate customers can make equal payments at nearly the same time.
Handle late and out-of-order events explicitly
Delivery order is not a reliable order-state machine. A refund notification can be observed before another event your application expects. Use the provider's documented resource state or retrieve authoritative payment details when needed, then apply allowed transitions. Keep the evidence used for the decision.
A late confirmation for a cancelled order needs an exception owner. Depending on the business policy, the team may restore the order, reserve inventory again or start a refund process. The handler should not invent that policy. External actions need their own idempotency and recovery path because a database rollback cannot undo a completed provider request.
Build the support and replay workflow
Test invalid signatures, duplicate delivery, a worker crash after committing the order, an unavailable provider and a confirmation after stock reservation expires. A replay tool should require a reason, show the current order state and retain an audit trail. Replaying must use the same business safeguards as the original delivery.
Monitor inbox age, processing failures and unresolved payment/order mismatches. Start with a sandbox and test event fixtures; then verify a controlled live flow according to the provider's rules. The acceptance criterion is a traceable payment-to-order decision with no repeated business effect. Conversion or revenue improvements require separate measurement and cannot be inferred from a successful webhook response.
Worked example and implementation boundary
In a fictional checkout, event E1 confirms payment P1 for order O1. The inbox accepts E1 once and the order transition links P1 to O1. The provider retries E1 after losing the acknowledgement; processing finds the prior result. A different event E2 about P1 must still obey the same domain transition, so event-level deduplication is not the only safeguard. If O1 was already cancelled, the configured exception policy decides the next action; the webhook handler does not invent a replacement order.
Trade-offs and limitations
Asynchronous processing shortens the receipt path but requires a visible pending state and backlog ownership. Synchronous processing is simpler only when its work fits a bounded response budget. Provider retry, signature and resource-state rules must be checked for the actual integration.
Common pitfalls
Do not acknowledge before durable receipt, trust the browser return as settlement evidence, or assume event arrival order equals business order. A retry button that bypasses normal state checks creates a second unsafe processing path.
Key takeaways
Verify the source, persist the message, deduplicate the effect and explain uncertain outcomes. Test the crash after local commit and before acknowledgement, because that is where an apparently successful integration can repeat work.
References and further reading
Stripe documentation — Webhook delivery and duplicate events
Related reading and implementation support
Related content
Backend Development, APIs and System Design
Backend systems, databases and APIs that connect your interfaces, apply business rules and keep information moving between the tools your team uses.
Business API Integration: Design for Failure and Recovery
Connect sales, accounting and operations with clear ownership, bounded retries and a recovery workflow your team can actually use.
Define the implementation boundary
Discuss payment webhook idempotency in the context of your current systems, decision owners and exception paths, then define a bounded first step.
Discuss your project
