mediumEngineering Practices#149

Exponential backoff with jitter

Prompt

Design the retry delays for a flaky API:

  1. backoffSchedule(retries, base, cap) → array of delays: base × 2^attempt, each capped at cap e.g. backoffSchedule(5, 100, 1000)[100, 200, 400, 800, 1000]
  2. withJitter(schedule, rand) → full jitter: each delay becomes rand() × delay (rand injected for testability; use Math.floor on the result)

Hints

Solution

Your Code

15 min

Tests

Click Run to test your code