Menu

Webhooks arrive out of order: make the state machine monotonic
📰

Webhooks arrive out of order: make the state machine monotonic

DEV Community: laravel·Keel·about 7 hours ago
#H5hwzLQc
#devtolaravel#devto#dev#event#subscription
Long article (1002 words) — no AI summary yet.
Reading 0:00
15s threshold

Every webhook integration starts with idempotency, because the docs say the same event can be delivered twice. Then a bug shows up that idempotency cannot explain: a subscription is active when it should be canceled, or an invoice is unpaid after the payment landed. Nothing was applied twice. Something was applied in the wrong order.

Providers do not promise ordering. Two events fired 200ms apart can arrive swapped after a retry, a queue backlog or a proxy that reconnects. Idempotency stops the same event from applying twice. It says nothing about a newer state being overwritten by an older one. Those are different guards and a handler needs both.

Three ways it actually breaks

A subscription.updated with status active arrives after subscription.canceled , because the canceled event was retried and the retry landed late. Last-write-wins leaves a canceled subscription active.

An invoice.paid arrives before invoice.created .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.