← All Exercises

Compute an Exponential Backoff Schedule

basicjavascript~20min

Background

Immediate retries amplify an outage. A computed backoff schedule bounds pressure on a struggling dependency and makes the worst-case wait explicit.

Problem

Generate the delay before each retry using exponential growth, capped at a maximum, and report the total waiting time.

Input

JSON object: { attempts, baseMs, factor, maxMs }

Output

JSON object: { delays: number[], totalMs: number }

Sample tests

Sample 1

Input: {"attempts":4,"baseMs":100,"factor":2,"maxMs":800}
Expected: {"delays":[100,200,400,800],"totalMs":1500}

Sample 2

Input: {"attempts":3,"baseMs":100,"factor":3,"maxMs":1000}
Expected: {"delays":[100,300,900],"totalMs":1300}

Your solution

Learning objective

Design retry behaviour that protects a degraded dependency.