Skip to content
DevLaunch home

Best practice · AI coding & owned software

Test Webhooks When Events Arrive Twice or Out of Order

Go beyond the successful demo and check how your integration handles duplicate deliveries, delays, and recovery.

By DevLaunchPublished

An integration demo usually shows one event arriving once. A form is submitted, a webhook reaches the application, and a record appears. Real workflows need a plan for less tidy conditions: the same delivery is replayed, a later event arrives first, or the destination succeeds just before the connection fails. Test those cases before the integration becomes a business dependency.

Define the event and the business action

Write down what the incoming message represents and what it is allowed to change. A subscription update might change access. A form submission might create an inquiry. Those actions need different checks, even if both arrive as JSON at an endpoint.

Keep the provider's delivery identifier separate from the identifier of the customer or business event. GitHub's webhook guidance, for example, identifies a delivery header useful for recognizing redeliveries. Other providers use different fields and retry rules, so check the documentation for the integration you actually use.

Replay the same delivery

In a test environment, send the same valid event twice. Confirm that you get the intended final state without a second business action. One inquiry should not produce duplicate records or repeated notifications simply because the sender retried.

The implementation may use a stored event identifier or another provider-supported idempotency mechanism. Ask the developer to show the record that prevents duplication and explain when it expires. A log message saying already processed is useful only if the underlying state supports that conclusion.

Reverse the sequence

Test an updated event arriving before an earlier event. For a fictional order workflow, a delivered status should not become processing because an old message was delayed. Decide which source establishes the current state and how the application detects stale updates.

Sometimes the safest response is to fetch the latest object from the provider rather than trusting the order of received messages. That choice depends on the provider and the business rules. The important point is to make the behavior deliberate and testable.

Interrupt the workflow after a partial success

Simulate a failure after the destination record is saved but before processing is marked complete. Then retry. This reveals whether recovery can inspect existing work or simply repeats every step.

Also verify authentication and event-type checks. A delivery that does not pass signature verification should not create business records. A valid delivery for an event your app does not support should be handled explicitly. Preserve enough diagnostic information to investigate without storing unnecessary sensitive payloads.

Keep a replay procedure

Document how an operator finds a failed event, checks whether its business action already happened, and retries safely. Test that procedure with synthetic data. Start with three cases: duplicate delivery, reversed order, and a failure after saving. Passing the ordinary demo is useful; passing these recovery cases is what makes the integration easier to operate.

Sources & further reading

Keep building

View topic →