Menu

1 / 2

A 100-Line Retry-with-Exponential-Backoff and Jitter for TypeScript

DEV Community·Gabriel Anhaia·6 months ago
#oCW2D9jr
#typescript#node#webdev#retry#attempt
Reading 0:00
15s threshold

Book: TypeScript in Production

Also by me: The TypeScript Library — the 5-book collection

My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools

Me: xgabriel.com | GitHub

You are on call. The payments provider returns a brief 503, the kind of routine ten-second hiccup that fills any large provider's status page. Every node in your service hits it on the same wall-clock second. Every node has the same retry policy: wait one second, retry, then two, then four. A second later every node retries. Two seconds after that every node retries again. The provider, which was nearly recovered, is now hammered by a synchronised wave of clients who all chose the same backoff. Their on-call sees a second spike worse than the first.

This is the thundering-herd failure mode, and a naive setTimeout(retry, base * 2 ** n) loop is what causes it. The fix is jitter.…

Continue reading — create a free account

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