Core Fundamentals

Request Timeout

0 of 6 complete

0%

Contents

Back|Core FundamentalsRequest Timeout
1/6
9 min left
  1. Home
  2. System Design: Foundation
  3. Core Fundamentals
  4. Request Timeout
Prerequisites
Connection Timeoutrequired
Related Topics
DNS (Domain Name System)Load Balancing & ProxiesUnicast RoutingLoad Balancing & ProxiesBroadcastLoad Balancing & ProxiesMulticastLoad Balancing & ProxiesAnycast RoutingLoad Balancing & Proxies
Previous lessonConnection TimeoutNext lessonSession Management

System Design

  • Foundation
  • Intermediate
  • Advanced
  • Capstone

AI Engineering

  • Foundation
  • Data, RAG and Agents
  • Evaluation, LLM Ops and Security

systemdesign.academy

  • Home
  • Glossary
  • Interview prep
  • Reviews
  • About
  • Privacy
  • Terms
1 of 6

Connected But Nobody's Talking

Last lesson, you learned about connection timeouts, the time to establish a connection. The handshake. The "hello, are you there?"

But the key point is that establishing a connection and getting an answer are two very different things. You can call a restaurant, someone can pick up the phone, and then put you on hold for 45 minutes. The connection was established instantly. The response never came.

A request timeout is the maximum time your client waits for the server to send back a complete response after the connection is already established.

Here's a real scenario I've seen multiple times: a backend service accepts a connection just fine, the handshake completes in 2ms. But then the service tries to run a database query that takes a lock, and the lock is held by another query, and that query is waiting on yet another lock. Deadlock. The service never responds. Without a request timeout, your client sits there forever, connected to a server that has absolutely nothing to say.

This is more insidious than a connection failure. At least when a connection fails, you get an error quickly. A service that connects but never responds is a silent killer.

What the Request Timeout Actually Covers

Once the connection is established, the actual request-response cycle begins:

  1. Client sends the request (headers, body)
  2. Server receives the request
  3. Server processes it (runs business logic, queries databases, calls other services)
  4. Server sends back the response (status code, headers, body)
  5. Client receives the complete response

The request timeout (also called read timeout or socket timeout depending on the library) covers steps 2 through 5. It starts ticking the moment your client finishes sending the request and stops when the complete response is received.

Why It's Usually Longer Than Connection Timeout

TimeoutTypical RangeWhy
Connection timeout1-5 secondsTCP handshake is fast. If it doesn't happen quickly, the server is unreachable.
Request timeout5-30 secondsServer legitimately needs time to process. A database query, an ML inference, a third-party API call, these take real time.

A connection timeout of 2 seconds with a request timeout of 15 seconds is a very common configuration. It says: "I expect to connect within 2 seconds, and I'll give the server up to 15 seconds to respond."

The Cascade Failure Without Timeouts

Watch how one slow database query, without a request timeout, can take down an entire system. Then see how adding timeouts prevents the cascade.

How to Choose the Right Value

Setting request timeouts requires understanding what the downstream service actually does.

Match the Timeout to the Operation

Operation TypeReasonable Request TimeoutExample
Simple read (cache hit, key lookup)1-3 secondsGET /users/123
Standard CRUD with database5-10 secondsPOST /orders
Complex query or aggregation10-30 secondsGET /analytics/report
File upload/download30-120 secondsPOST /files/upload
Long-running job (synchronous)Don't. Use async instead.Report generation

Timeouts and Retries: A Dangerous Combo

When a request times out, the natural instinct is to retry. Usually that's fine. But there's a trap.

The Retry Storm

Imagine Service A times out calling Service B after 5 seconds. Service A retries. Meanwhile, Service B is actually just overloaded, it's processing requests slowly but not dead. The retry adds to Service B's queue. A hundred other clients are doing the same thing. Now Service B is getting twice the traffic, the original requests plus all the retries. It gets even more overloaded. Timeouts increase. More retries fire. More load. The system spirals into collapse.

This is called a retry storm, and it's one of the most common causes of prolonged outages.

How to Retry Safely

Quick Check

Knowledge Check

3 questions - Score 80% to pass

Q1

What is the key difference between a connection timeout and a request timeout?

Q2

Service A (timeout: 10s) calls Service B (timeout: 12s to Service C). What's wrong with this setup?

Q3

A service is overloaded and responding slowly. Your client times out and retries immediately. 500 other clients do the same. What happens next?

The Cardinal Rule: Never Use the Same Timeout for Everything

I've seen codebases that set a global 30-second timeout for all HTTP calls. This means a simple health check endpoint, which should respond in 50ms, gets a 30-second grace period before failing. If that health check hangs, your won't know the service is unhealthy for 30 seconds. That's 30 seconds of sending traffic to a dead instance.

Different operations deserve different timeouts. Your health check might get 2 seconds. Your payment processing might get 15 seconds. Your report generation endpoint should be async, not synchronous with a long timeout.

Timeout Budgets

In architectures, request timeouts need to account for the full call chain.

Say Service A calls Service B, which calls Service C:

  • Service A's timeout to Service B: 10 seconds
  • Service B's timeout to Service C: 8 seconds

Service B's timeout must be less than Service A's. If Service B waits 12 seconds for Service C, but Service A already gave up after 10, Service B is doing useless work, the caller already moved on. The response from Service C arrives, gets passed back to B, which passes it to... Nobody. Service A hung up 2 seconds ago.

Rule of thumb: Each hop in the chain should have a timeout that's 70-80% of the caller's timeout, leaving room for network transit and processing overhead.

Exponential backoff, don't retry immediately. Wait 1 second, then 2, then 4, then 8. Give the struggling service time to recover.

  • Jitter, add randomness to your backoff. If 1,000 clients all retry at exactly 1 second, you get another spike. Add random delay (e.g., 1 second + random 0-500ms) to spread retries out.

    1. Max retries, cap it at 2-3 retries. If a request fails 3 times, it's not going to succeed on the 4th. Fail and tell the user.

    2. Only retry operations, retrying a GET is always safe. Retrying a POST that creates a payment? You might charge someone twice. (We'll cover idempotency in a later lesson.)