Loading
0x10Lesson 2 of 9

Use timeouts and retries safely

Choose retry policies that recover from transient failures without multiplying work.

14 min 5-question quiz
By the end of this lesson you can
  • Explain deadlines, bounded retries, backoff, jitter, and idempotency keys.

Set a deadline for each request so callers do not wait forever. Retry only failures that may be transient, cap attempts, and use exponential backoff with jitter so many clients do not retry together. A retry can repeat an operation whose first result was merely delayed. Idempotent operations have the same effect when repeated; an idempotency key can let a server recognize duplicate submissions.

Real clients randomize delays and respect an overall deadline. A retry policy should also avoid retrying permanent errors such as invalid input.

Practice: survive an outage with retries

Try it

Up to 15 XP

What do your retries do to a recovering server?

The server goes down for ten ticks and drops every open connection. The red and green marks show when it fails and returns. Compare the policies:

  1. Retry immediately. How far above capacity does the load go, and how many requests give up? They burned every attempt while the server was still down.
  2. Exponential backoff. Nothing gives up, because the retries outlast the outage. But look at the spikes: clients that failed together retry together.
  3. Turn on jitter. What happens to the biggest spike?
  4. No retries has the calmest chart. What did it cost?
Retry policy
  • Requests
  • Server capacity
050100150200061218243036424854Time (ticks)Requests
Show the numbers as a table
Time (ticks)RequestsServer capacity
01015
11015
21015
31015
41015
51015
61015
71015
81015
91015
107015
118015
129015
1310015
1411015
1512015
166015
176015
186015
196015
206015
215515
225015
234515
244015
253515
263015
272515
282015
291515
301015
311015
321015
331015
341015
351015
361015
371015
381015
391015
401015
411015
421015
431015
441015
451015
461015
471015
481015
491015
501015
511015
521015
531015
541015
551015
561015
571015
581015
591015
Busiest moment
120 (capacity 15)
Failed attempts
1035
Requests given up on
110
Overloaded after it came back
9 ticks

Practice: is this safe to repeat?

Try it

Up to 15 XP

Idempotent or not?

Imagine the operation runs twice because a retry arrived. Would the result be different?

0 of 6 sortedScore 0/0
  • “Set the customer’s email to ana@example.com.”

  • “Add $10 to the account balance.”

  • “Read an order’s status.”

  • “Send a welcome email.”

  • “Delete order 123.”

  • “Create a new order.”

Try it

Up to 15 XP

Should the client retry?

Retry only when a second attempt could turn out differently.

0 of 5 sortedScore 0/0
  • “503 Service Unavailable”

  • “400 Bad Request”

  • “Connection reset”

  • “403 Forbidden”

  • “429 Too Many Requests”

Key takeaways

  • Use an overall deadline and bounded attempts.

  • Backoff plus jitter reduces synchronized retry load.

  • Idempotency keys help safely repeat side-effecting requests.

Lesson quiz

5 questions · pass with 4 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…