Stripe webhook events arrive out of order: how to handle it safely
November 10, 2026
Your logs show customer.subscription.updated being processed before customer.subscription.created for the same subscription. Or a customer who upgraded ends up on the old plan in your database. Nothing is broken on Stripe’s side: Stripe documents that it does not guarantee the order in which events are delivered.
Combined with retries (see why the same event can arrive twice), this means your handler has to be correct no matter which event shows up first, second, or twice.
How it goes wrong
- Update before create. A handler that does an
UPDATEfinds no row, because the “created” event is still in flight. The update is silently lost. - Stale overwrites fresh. Two quick changes produce two events. If the older one is delivered last, it overwrites the newer state with outdated data.
- Retries reorder everything. One event fails once and is retried later, so it lands after events that were created after it.
- Parallel workers. Two serverless invocations process two events for the same object at the same time, and whichever finishes last wins.
The fragile version
// The version that works in testing and corrupts data in production
case 'customer.subscription.updated': {
const sub = event.data.object as Stripe.Subscription
await db.subscriptions.update({ // throws or no-ops if "created" has not arrived yet
where: { id: sub.id },
data: { status: sub.status }, // may be an OLDER state than what you already stored
})
}The fix: treat the event as a notification, not as the data
An event payload is a snapshot taken when the event was created. By the time you process it, the object may have changed again. So use the event only to learn which object changed, then ask Stripe for the current state and write that with an upsert:
// Re-fetch the current object and upsert it. Order stops mattering.
case 'customer.subscription.created':
case 'customer.subscription.updated':
case 'customer.subscription.deleted': {
const eventSub = event.data.object as Stripe.Subscription
// The payload is a snapshot from when the event was created.
// Ask Stripe for the state as it is right now.
const current = await stripe.subscriptions.retrieve(eventSub.id)
await db.subscriptions.upsert({
where: { id: current.id },
create: { id: current.id, status: current.status },
update: { status: current.status },
})
break
}Two things make this robust. First, retrieve always returns the latest state, so a late delivery of an old event writes the same current data as a fresh one. Second, upsert means it does not matter whether the “created” event has arrived yet. The cost is one extra API call per event, which is cheap next to a corrupted subscription table.
Why not just compare timestamps?
You can store event.created and ignore events older than the last one you applied. It helps, but created has one-second resolution, so two changes in the same second tie, and it does nothing for the missing-row problem. Re-fetching plus upsert covers both. Use timestamps as an extra guard, not as the only one.
Order bugs are silent
The nasty part is that none of this raises an error. The handler returns 200, Stripe is happy, and your data is wrong for weeks. That is the same failure mode described in your Stripe webhook returns 200, but it didn’t work. If events are also being rejected before they reach your code, start with signature verification failures.
Find out if your data already drifted
The quickest check is to compare Stripe against your database directly. Run this reconciliation script once, or let Venwai do it every day with a read-only Stripe key and alert you in Slack, Discord, Telegram, or email the moment a subscription and your app disagree.
Free while it’s in beta, no card required: venwai.com.
Venwai compares Stripe with who your app actually lets in, once a day, using a read-only key. It alerts you the moment they disagree. Free while in beta, no card required.
Check my Stripe for free