Webhooks & Events

Ordering and Out-of-Order Events

Webhook deliveries can arrive in a different order than the events occurred. Design as if they will.

What you'll learn

  • Explain why deliveries may arrive out of sequence
  • Identify which workflows are sensitive to ordering
  • Use timestamps or versions to reconcile sequence
  • Apply state-based reasoning instead of assuming order

6 min read

Why order is not guaranteed

It is tempting to assume webhooks arrive in the same order the events actually happened, but many systems make no such promise, and relying on one quietly is a recipe for bugs. Retries, parallel delivery workers, and ordinary network variability can all shuffle the sequence along the way. An updated event might land before the created event it logically follows, simply because the second delivery took a faster path.

If your processing silently assumes a strict order, these reorderings produce subtle and intermittent failures: a record updated before it appears to exist, a cancellation applied before the thing it is meant to cancel ever arrives. The safe stance is to treat ordering as best-effort at most, and to build logic that copes gracefully when the order turns out to be wrong, because eventually it will.

Which workflows care

Not every integration is actually sensitive to order, and it is worth knowing which of yours are. If each event is genuinely independent — a notification, a logged action, an audit entry — then the sequence may not matter at all, and you can process events freely as they arrive. Ordering only starts to bite when events describe transitions of the same entity, where the correct final state depends on applying the changes in the right sequence.

Spotting these order-sensitive cases early is half the battle won. Ask yourself a simple question for each flow: does processing event B incorrectly depend on whether event A came first? If the answer is yes, you need a deliberate strategy beyond hoping the network cooperates. If the answer is no, you can keep that handler simple and spend your effort elsewhere.

Reconcile with timestamps or versions

The common and reliable fix is to carry a version number or a timestamp in each event that describes the state of the underlying entity, and then to ignore any event that is older than what you have already applied. This way the newest information always wins, no matter the order in which the deliveries happen to reach you.

if (event.version <= record.version) {
  return respond(200); // stale, skip
}
applyEvent(event);
record.version = event.version;

With this guard in place, a late-arriving older event simply cannot overwrite newer data, because the version check rejects it before it does any harm. It is a small amount of code that eliminates an entire family of ordering bugs.

Think in states, not sequences

A durable mindset, beyond any single technique, is to treat each event as a statement about the world rather than a step that must follow the previous one. Where the provider allows it, prefer events that convey the full current state of the entity, so that applying the latest one is correct even if you happened to miss some earlier events entirely. That framing makes whole classes of ordering problems melt away.

When you truly do need strict ordering and cannot get it from the stream alone, a periodic reconciliation against authoritative state closes the remaining gaps, much as described in replaying missed events. Whether a given provider's events carry version fields you can rely on is documented in the API documentation.

Key takeaways

  • Deliveries can arrive out of order due to retries and parallelism
  • Only state-transition workflows are genuinely sensitive to ordering
  • A version or timestamp lets you discard stale events safely
  • Prefer state-based reasoning over assuming a strict sequence

FAQ

Are webhooks delivered in order?

Do not assume so. Retries, concurrent workers, and network timing can reorder deliveries, so build processing that tolerates events arriving out of sequence.

How do I handle an event that arrives late?

Compare a version or timestamp on the event against your stored state and ignore anything older than what you have applied, so newer data is never overwritten.

Does every integration need ordering logic?

No. Independent events that do not depend on each other can be processed as they arrive. Ordering only matters when events describe transitions of the same entity.

Integrate with Merion

Ready to build?

Read the API reference, grab the OpenAPI spec, and ship a resilient integration.