Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Courses/Reliability and Failure
Lesson 5 of 24

Timeouts and deadlines

Put a time limit on every remote call, choose it from data, and propagate it down the call chain.

15 min read

Every remote call needs a timeout

Without a timeout, a call to a hung dependency waits forever, holding a thread, a connection and memory. Consider a service with 200 worker threads whose dependency starts hanging for 30 seconds per call: its capacity drops from thousands of requests per second to 200 / 30, under 7 per second. Many client libraries default to no timeout or to several minutes, so set connect and request timeouts explicitly on every HTTP client, database driver and queue client.

Choosing the value

Base timeouts on measured latency, not guesses. A common starting point is slightly above the dependency's p99.9 under normal load: if p99.9 is 250 ms, a 300 to 500 ms timeout cuts off pathological calls without failing healthy slow ones. Too short and you fail requests that would have succeeded, then retry them and add load. Too long and you hold resources while the user has already given up.

  • Connect timeout: short, around 100 ms to 1 s; failing to connect is quick to detect
  • Request timeout: from the dependency's latency distribution
  • Overall deadline: from what the user will tolerate

Deadlines propagate

Nested timeouts must shrink as you go deeper. If the edge gives a request 2 seconds and the API spends 1.5 seconds before calling the database with its own 2-second timeout, the database keeps working long after the user has received an error. Pass the remaining deadline downstream (gRPC does this natively) and have each service stop work once the deadline passes. Wasted work for abandoned requests is a major source of overload during incidents.

Timeouts create ambiguity

A timeout tells you only that you stopped waiting. The remote side may have done the work, partly done it, or never received it. For reads that does not matter. For writes it matters a lot: a timed-out payment might have been charged. Pair timeouts on writes with idempotency keys so a retry cannot double-apply, and with a way to query the outcome later. Log enough context on every timeout to reconcile later.

Key takeaways

  • Set explicit connect and request timeouts on every client; library defaults are often infinite
  • Choose timeouts from the dependency's p99 to p99.9 latency, not by guessing
  • Propagate the remaining deadline so downstream services stop work nobody is waiting for
  • A timed-out write has an unknown outcome; make it safe to retry

Sign in to track lessons and earn badges.

Health checks and failoverRetries, backoff and retry storms

Coming up

Course: 0/24 lessons · 0/10 challenges0%

Build it on the canvas, pass the review (70+) and mark it complete to count it toward the course badge.

  1. 1/10Design a Web CrawlerUse per-host timeouts, bounded retries and bulkheads so one slow or hostile site never stalls the whole crawl.Medium
  2. 2/10Design a Weather API ProxyCache provider responses and serve stale data behind a circuit breaker when the paid upstream API is down.
Easy
All 10 challenges →