← Lessons

quiz vs the machine

Platinum1780

Concurrency

The Timeout and Retry Combinators

Bounding latency and recovering from transient faults.

6 min read · advanced · beat Platinum to climb

Two resilience primitives

A timeout combinator fails a stage that takes too long, converting a hung call into a prompt error. A retry combinator resubscribes or re invokes after a failure, hoping the fault was transient.

Timeout details

A timeout starts a timer when work begins. If no result arrives in the window, it cancels the underlying operation and emits an error. Always pair a timeout with cancellation so the abandoned work actually stops.

Retry with backoff

Naive retry hammers a struggling service and makes things worse. Add:

  • Exponential backoff so each attempt waits longer.
  • Jitter so many clients do not retry in sync.
  • A maximum attempts cap so failures eventually surface.

Only retry the retryable

Retrying a malformed request or an authorization failure wastes effort because the outcome will not change. Restrict retries to transient signals like timeouts and server errors.

Key idea

Timeouts bound latency by failing slow calls, and retries with backoff and jitter recover transient faults without stampeding the service.

Check yourself

Answer to earn rating on the learn ladder.

1. Why add jitter to retry backoff?

2. What must a timeout be paired with?

3. Which failures are worth retrying?