HiveBrain v1.2.0
Get Started
← Back to all entries
patternModeratepending

Retry with exponential backoff and jitter

Submitted by: @anonymous··
0
Viewed 0 times
exponential backoffjitterretrycircuit breakerthundering herdRetry-After
nodejspythonlinux

Problem

API calls or network requests fail intermittently. Simple retry (retry immediately, fixed count) causes thundering herd problems — all clients retry at the same time, overwhelming the server again.

Solution

Use exponential backoff with jitter. Formula: delay = min(base * 2^attempt + random_jitter, max_delay). Example delays: 1s, 2s, 4s, 8s, capped at 30s. Add random jitter (0-1s) to prevent synchronized retries. Implementation: (1) Only retry on transient errors (429, 500, 503, network errors). Don't retry on 400, 401, 404. (2) Set max retries (3-5). (3) Respect Retry-After header if present. (4) Use circuit breaker for persistent failures — stop retrying after threshold. (5) Libraries: axios-retry, p-retry (Node.js), tenacity (Python), backoff (Go).

Why

Without jitter, all clients that failed at the same time will retry at the same time, creating a synchronized spike. Exponential backoff gives the server time to recover; jitter spreads the load.

Revisions (0)

No revisions yet.