Webhooks are async by design — and that means sometimes events arrive out of order.
I hit this bug last week:
Expected customer.created before customer.updated.
But in production, updated arrived first.
My app tried to update a record that didn’t exist yet.
Why This Happens:
- Providers don’t guarantee strict ordering.
- Retries or network latency shuffle delivery.
- Parallel processing makes it worse.
The Fix:
- Design for eventual consistency: Never assume order.
- Fetch latest state: On receiving an event, call the provider’s API to confirm resource state.
- Queue & reorder: Use Kafka/RabbitMQ/SQS to buffer events and enforce ordering.
- Idempotency + retries: Combine with deduplication logic.
Example (Stripe, Node.js):
if (!db.customer[event.data.id]) {
const customer = await stripe.customers.retrieve(event.data.id);
db.customer[customer.id] = customer;
}
Takeaway:
Out‑of‑order events are sneaky but solvable. Build for eventual consistency, fetch latest state, and use queues if needed.
I’ve been building Hookmetry to replay events in different orders — so you can test how your system handles async chaos before production.
💬 Have you faced out‑of‑order events? Did you solve it with API fetches, queues, or another trick? Share your fix — let’s build a best‑practice thread together.
Top comments (0)