CodingNeed.

Bridge · From syntax to engineering · 25 MIN

Plan bounded retries

A retry policy needs both a delay limit and a total budget.

Retrying every failure can multiply traffic exactly when a service is struggling. First decide which failures are retryable and whether repeating the operation is safe. This exercise models only the schedule: double the delay, cap it, and stop before the total waiting budget is exceeded. A deterministic calculation is easy to test. A production scheduler also needs cancellation, a deadline covering request time, and jitter to avoid clients retrying together. Do not retry a payment write without a stable idempotency key.

Write a small contract first, then test how the implementation behaves at its boundaries.

Read the example

console.log(Math.min(100 * 2, 150));
Check the expected output
150

Your challenge

Input {attempts:nonnegative integer, base:positive integer, cap:positive integer, budget:nonnegative integer}. Return up to attempts delays. Start at min(base,cap), double up to cap, and stop if adding a delay would exceed budget.

Solution cost: O(a), a emitted delays. time · O(a) for the returned schedule. space

Common trap

A cap on each delay does not limit the total time spent retrying.

Further reading: MDN AbortSignal

Next lesson: Project · Apply each ledger event once

Essential cookies keep your account signed in. Optional analytics is not configured on this site. Your choice does not affect access to lessons.

Read the Privacy Policy. You can change this choice in the footer.