Skip to content

L17 Timeouts and retries

21 minSuggested first: L16 Clients and redirects

Outcome

Calculate a bounded retry schedule and decide when it is unsafe to retry an operation.

Learn

A timeout bounds how long you wait; it doesn't prove the server did nothing. A retry policy says which failures are eligible, how many attempts are allowed, and how long to wait between them. Backoff makes the waits grow; jitter spreads retries out so callers don't all retry at once.

An idempotent operation has the same intended effect when it's repeated; its responses needn't match.

Worked example

The policy allows three attempts in all, a 100 ms timeout per attempt, waits of 50 ms then 100 ms, and no jitter. Every attempt times out. When does the caller give up?

A toy retry scheduleText
Attempt 1: 0–100 ms      wait 50 ms
Attempt 2: 150–250 ms    wait 100 ms
Attempt 3: 350–450 ms    stop
Predict first, then show the worked explanation

Attempts start at 0, 150 and 350 ms. The last timeout arrives at 450 ms, assuming no other overhead, and no fourth attempt happens because three is the total.

Practice and check

Guided practice

Practice, not scored

This time attempt 2 succeeds immediately, at 150 ms. Which later attempt runs?

Choose one answer

Exit check

Counts toward completion

A request to create an order times out after it was sent. What does the timeout establish?

Choose one answer

Common mistake

Mixing up retries and attempts. Note whether a count includes the first attempt. In real systems, account for an overall deadline as well as per-attempt timers.

Practice on a real repository

Try the first puzzle below, then read the policy conditions in the second.

Related topics: Retries and timeouts

Practice is optional. Solving a puzzle doesn't complete a lesson, and lessons never change a puzzle's points.

References