Menu

Webhooks arrive late, twice, or out of order: a small reducer for payment and swap status
📰

Webhooks arrive late, twice, or out of order: a small reducer for payment and swap status

DEV Community: javascript·TEMST·2 days ago
#60TE1yWE
#devtojavascript#devto#dev#order#status
Long article (1323 words) — no AI summary yet.
Reading 0:00
15s threshold

If your app shows the status of something that happens somewhere else (a payment, a shipment, a crypto swap), you usually get updates two ways: the provider sends webhooks, and you poll its API as a backup. Both paths feed the same screen.

That's where a quiet bug lives. Webhooks are delivered at least once, so the same event can show up twice. They can arrive out of order after a retry. And a poll that started a second before a webhook can finish a second after it, carrying older data. If every update simply overwrites the stored status, your user sees "sending", then "confirming" again, then "sending". On a screen that shows their money, that looks like something went wrong.

The fix is small: run every update, from either path, through one function that decides whether it's allowed to change anything.

Don't rank the statuses

The first idea most people have is to give each status a number and only move forward.…

Continue reading — create a free account

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