Retry Backoff Schedule

medium · distributed-systems, resilience, sre

Retry Backoff Schedule

You are simulating a retry policy with exponential backoff. An initial attempt happens at start time. After each failure, the next attempt is scheduled after a delay:

delay = min(maxDelay, baseDelay * 2^(failuresSoFar))

Where failuresSoFar starts at 0 for the first failure.

Given the outcomes of attempts in order, return the scheduled times of the attempts that actually occur. Stop when an attempt succeeds.

Function signature

func RetrySchedule(start int, outcomes []bool, baseDelay int, maxDelay int) []int

Example

start=0, baseDelay=5, maxDelay=20
outcomes = [false, false, true]

attempt times:
- t=0 (fail)
- t=5 (fail)   delay=5
- t=15 (success) delay=10

output = [0,5,15]

Constraints

  • 0 <= len(outcomes) <= 100000
  • 0 <= start, baseDelay, maxDelay <= 1_000_000

Notes

  • If outcomes is empty, return an empty slice.
  • If baseDelay is 0, all retries happen at the same time as the previous attempt.
Run tests to see results
No issues detected