Skip to content
RED SAGSkills

Exponential Backoff Timeline

An HTTP client retries failed calls with exponential backoff. The first attempt starts at time 0. Before retry number k (k = 1, 2, ...) it waits min(maxDelayMs, baseMs * factor^(k - 1)) milliseconds after the previous attempt started. It makes at most maxRetries retries, so at most maxRetries + 1 attempts.

outcomes[i] is true if attempt i succeeds. The client stops as soon as an attempt succeeds.

Return { attemptStarts, succeeded }: the start time of every attempt that was made, and whether the last one succeeded.

Example 1

Input: outcomes = [false,false,true], baseMs = 100, factor = 2, maxDelayMs = 10000, maxRetries = 5
Output: {"attemptStarts":[0,100,300],"succeeded":true}
Explanation: Waits 100 then 200 ms; the third attempt succeeds.

Example 2

Input: outcomes = [false,false,false,false,false], baseMs = 100, factor = 2, maxDelayMs = 500, maxRetries = 4
Output: {"attemptStarts":[0,100,300,700,1200],"succeeded":false}
Explanation: Delays 100, 200, 400, then capped at 500.

Constraints

  • outcomes.length >= maxRetries + 1
  • 0 <= maxRetries <= 30
  • 1 <= baseMs <= 10^4
  • 1 <= factor <= 4 (integer)
  • baseMs <= maxDelayMs <= 10^6
Hint 1

Keep a running clock and add each capped delay to it.

Good practice for: Backend Developer, Site Reliability Engineer, Cloud Engineer, DevOps Engineer, Mobile App Developer, Automation Test Engineer

Run checks your code on 3 sample tests. Submit runs all 7 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.