INFINITE UPSIDE

Technology and operations

Why Did a Webhook Arrive After the Event It Followed?

Delivery order is not a reliable substitute for the order in which the business changed.

The cancellation arrived first. The update arrived second. The order looked alive again. A customer changed an order and then canceled it, but a delayed “order changed” notification reached the receiving system after the cancellation. The network did not necessarily invent a new order; the integration may have treated arrival time as a reliable business timeline.

Webhook deliveries can arrive out of order, and a receiver needs a rule for reconciling them with current state. GitHub’s webhook troubleshooting guide explicitly says delivery order may differ from event order and points to timestamps in the payload. Each provider’s events, identifiers, retry rules, and current-object API must be understood on their own terms.

Three clocks, one order

In an illustrative order, call the change event A and the cancellation event B. A occurs at 10:00:00; B occurs at 10:00:05. The receiver sees B at 10:00:06 and A at 10:00:12. A last-arrival-wins rule writes “changed” after “canceled,” even though A describes an earlier event. That is a local ordering error, not evidence that the provider reversed the cancellation.

There are at least three times to distinguish: when the business event occurred, when the provider created its event record, and when the receiver processed the delivery. A timestamp can help, but it is not always a unique sequence number. Two events may share a timestamp, represent different objects, or use clocks and precision that do not establish a total order. Read the provider’s actual guarantees before building a comparison around a field.

Also distinguish an event from a delivery attempt. A provider may retry the same event, or an operator may redeliver a failed webhook. A receiver that counts every attempt as a separate sale can duplicate a business effect even if the events are otherwise in order. Conversely, deduplicating exact repeats does not solve a late, legitimate event describing an earlier state.

Decide what the notification represents

Some webhooks carry a snapshot of an object at a point in time. Others announce that something changed and expect the receiver to retrieve more information. Some providers distinguish event creation from delivery status. A field named “status” should not be assumed to be a live view merely because it appears in a fresh HTTP request.

For a stateful integration, one approach is to treat a notification as a prompt to retrieve the current object using an authorized, documented provider API. Another is to apply event changes only when a reliable version or sequence establishes that they are newer. Each approach has tradeoffs. A current-object lookup can add latency and fail temporarily; a sequence-based approach depends on the provider actually guaranteeing the relevant ordering semantics.

Consider two hypothetical notifications that refer to the same order: “address updated” and “canceled.” If the receiving service only needs the current status for an internal dashboard, fetching the latest permitted order representation may be preferable to replaying snapshots blindly. If it needs a complete audit of every address change, a current snapshot alone is insufficient. The integration may need to retain the events as evidence while maintaining a separate current-state projection.

Keep evidence separate from effects

Store enough information to identify the provider event and its processing history without putting private payloads, credentials, or customer details into general logs. A useful record might include the provider’s immutable event ID, event type, object reference, event time where defined, receipt time, verification result, processing status, and a safe correlation identifier. Retention and access should follow the organization’s existing privacy policy.

Before accepting an event as genuine, verify the provider’s documented signature or other authentication mechanism. A valid signature supports authenticity and integrity under that mechanism; it does not prove that the event is the newest event for the object. The system should also verify that the event belongs to the expected account and environment. Test and production identifiers that look similar are not interchangeable.

Then make the side effect idempotent at the appropriate business boundary. If processing an event creates a record or triggers a notification, record whether that effect was already completed and use the provider’s or the application’s stable identifier according to its rules. Our guide to idempotency keys explains why a retry needs a stable identity. Deduplication should not discard two genuinely different events simply because they concern the same order.

What should happen when an earlier event arrives late?

Do not apply a universal answer to every event. A late “address changed” event might still belong in an audit log even though it should not reactivate a canceled order. A late payment-related event may require a separate reconciliation because money movement has its own identifiers, states, and consequences. The receiver needs explicit transitions and a way to flag an event it cannot safely classify.

A fictional state table can make the rule visible: a cancellation at version 12 follows an update at version 11; the receiver has already stored version 12. If the provider actually guarantees comparable per-object versions and the event is version 11, the receiver can retain the event while declining to overwrite the newer projection. If the provider offers no such version guarantee, pretending that a timestamp or numeric-looking ID is a sequence can create a false sense of safety.

Out-of-order delivery can also expose missing history. An update may arrive before the receiver has seen the creation event. The system can queue the event for bounded retry, retrieve the object if authorized, or flag it for reconciliation. The right behavior depends on the provider and product. Dropping it silently or creating a partial object with guessed fields makes later investigation harder.

Respond quickly without losing the work

Webhook endpoints commonly acknowledge receipt and process work asynchronously, but the acknowledgment must have a clear meaning. If the endpoint returns success before preserving enough information to recover from a crash, the sender may believe delivery succeeded while the business effect is lost. If it waits for every downstream task, a slow dependency can cause timeouts and retries. Design the durable handoff and acknowledgment together.

Use the provider’s documented retry and redelivery behavior. GitHub’s troubleshooting guide, for example, distinguishes failed deliveries, delayed deliveries, and out-of-order deliveries; another provider can behave differently. Do not replay a real payment or customer notification merely to test a fix. Use an isolated test environment and verify exactly which effects are permitted before redriving any real event.

Monitor both the queue and the state it is meant to maintain. A healthy-looking endpoint can accept every request while a worker fails to update the projection. Track failures, age of unprocessed work, duplicate attempts, reconciliation discrepancies, and the time of the last successful end-to-end check. An empty queue is useful evidence about the queue, not proof that every source event was received.

The race between two workers

Out-of-order arrival is only half the race. Suppose an update and a cancellation arrive in the correct order, but two workers process them at the same time. The update worker reads version 10 and pauses. The cancellation worker reads version 10, writes version 12, and finishes. The update worker resumes and writes its older version 11. A queue that received messages in order did not prevent the final state from moving backward.

One way to address this, when the provider supplies a reliable comparable version, is to make the version check and state update one atomic operation. A conditional write can apply version 11 only if the stored version is older; after version 12 is stored, that attempt must affect no row. The exact implementation depends on the database and the version semantics. If the provider does not guarantee comparable versions for the object, a conditional write built on an invented ordering field merely makes the wrong rule atomic.

Alternatively, an integration may serialize processing for an object, or use a notification to fetch and reconcile current provider state. Serialization has throughput and failure-handling costs, and a fetch can race with another update or fail temporarily. Neither technique removes the need for idempotent effects. Keep the event record, state transition, and effect receipt related so an operator can tell whether the event was received, whether it changed the projection, and whether a separate effect actually happened.

Test this with an isolated fixture: deliver the update and cancellation in both arrival orders, run their workers with deliberately interleaved steps, and deliver one event twice. Then simulate a crash after durable receipt but before processing. The expected outcome should state both the current projection and the retained history. A passing HTTP response alone is not the outcome being tested.

The system cannot reconcile what it never recorded

Choose a bounded sample of provider objects and compare their current authorized state with the local projection. Record the source, retrieval time, object identifier, observed state, and any correction. A difference can reflect a late event, a missing event, a processing failure, or a mapping error. Investigate before changing records; a comparison does not itself authorize a refund, message, payment, or replay.

For the fictional canceled order, the desired result is a timeline that preserves both the address update and the later cancellation, while the current projection remains canceled. The integration succeeds when it can explain how it reached that state and recover from a delayed or repeated delivery—not merely when the last webhook happened to win.

Explore Infinite Upside

For Vijay Sheth’s personal accounts, read Infinite Upside: Building Wealth With Room to Live, published by Sheth Capital, Inc.

Find your edition · Chapter companion

ABOUT THE CONTRIBUTOR

Luna Lim

DIRECTOR OF FINANCIAL RESEARCH & EDITORIAL STRATEGY

SHETH CAPITAL, INC.

Luna Lim writes about business, investing, and the judgment behind financial decisions. She joined PCH Exotics Inc. as Director of Operations in 2022, working across La Jolla and Miami. Today, she reports directly to Vijay Sheth at Sheth Capital, Inc., bringing an operator’s perspective to the ideas she covers.

Based in Pacific Beach, California, Luna is curious about the people behind the numbers: what they’re building, how they weigh uncertainty, and what makes a risk worth taking. Her articles for Infinite Upside follow those questions through the details, with clear explanations and a feel for how decisions play out in everyday business.

More from Luna Lim

The Infinite Upside store