How to process webhooks without duplicate actions
Design an event handler that can receive repeated and out-of-order notifications while keeping business actions consistent.
Separate the notification from the action
A provider may deliver an order-paid notification again when it does not receive a response. The business outcome is one packing request for that order. Model the receipt and the packing request as separate steps so a second notification does not create another package.
Use the event identifier provided by the source to recognize a replay. Scope that identifier to its provider and account if needed. Also use a business identifier, such as order ID, when distinct events could request the same packing task.
Record receipt before processing
Store enough about the event to recognize it and continue processing, then acknowledge delivery. In a background worker, look at the recorded event, apply the relevant rule, and mark the resulting work complete after you have confirmed its outcome.
If the destination write and the completion marker are in different systems, a failure can happen between them. Use a destination request key or lookup that lets you confirm the existing result before creating any record during recovery.
Handle events in business order
A payment confirmation may reach your system after a refund notification. When order matters, check the event version or fetch the current state before making a change. A timestamp is useful context, and a source record version may provide a stronger ordering signal.
Define which transitions your workflow accepts. A refunded order should remain refunded when an older paid event arrives. If the state and event cannot be reconciled automatically, preserve the reason so an operator can decide what to do.
Make notification history useful
Record the source event ID, associated business record, observed status, and action result. Keep only the information the operator needs to trace the workflow. Those references help distinguish an already handled notification from work that needs attention.
Test the same notification twice, two different notifications for the same order, and a delayed event after a later state change. Review the downstream records after each test so validation covers the actual business actions.