What you're building
A retry scheduler with exponential backoff — the algorithm that makes every production HTTP client, database connector, and job queue resilient to transient failures.
AWS SDKs, Axios retry plugins, PostgreSQL connection pools, and Kubernetes pod restart policies all implement this exact pattern.
The algorithm
attempt 1: immediate
attempt 2: wait baseMs * 2^0 (= baseMs)
attempt 3: wait baseMs * 2^1
attempt 4: wait baseMs * 2^2
...
cap each wait at maxMs
add optional jitter (±20%) to prevent thundering herd
Requirements
Build a pure, synchronous BackoffSchedule class (no async, no setTimeout — the sandbox is sync-only).
BackoffSchedule(maxAttempts, baseMs, maxMs):
nextDelay(attemptIndex)— given attempt index (0 = first retry after initial failure), return the delay in milliseconds that should be waited before this retry. Return-1ifattemptIndex >= maxAttempts.shouldRetry(attemptIndex)— returntrueif another attempt is allowed.delays()— return an array of all scheduled delays (length = maxAttempts).
No jitter required for tests (keep it deterministic). Keep all delays between baseMs and maxMs.
Stretch goals
- Add optional
jitterfactor (0–1) that randomises delay by ±(factor * delay). totalWaitMs()— sum of all delays.
What this proves
You understand exponential backoff math, boundary clamping, and how to design retry policies that are both safe and testable without timers.
⚡ 50 XP
solution.jsRuns in your browser
Loading editor…
Tests4 to pass
first retry uses baseMs
delays double each attempt
delay is capped at maxMs
nextDelay returns -1 past maxAttempts
Run your code to check these.