Network Timeouts: How Long Should a Service Wait?
📑 On this page
- A concrete example: calculating shipping
- Why waiting forever is dangerous
- A timeout is not proof of failure
- Connection timeouts
- Request and response timeouts
- Deadlines versus durations
- Timeout budgets
- Choosing a timeout
- Tail latency
- Timeout propagation
- Cancellation
- Retrying after timeout
- Fallback behavior
- Timeouts and circuit breakers
- Queueing time
- Observability
- Testing timeout behavior
- User feedback
- A practical timeout checklist
- Knowledge check
- The one idea to remember
A remote service can be slow without being completely broken.
It may be overloaded, separated by a congested network, waiting for its own dependency, or processing a request whose reply will never reach the caller. Without a waiting limit, one stuck interaction can hold resources indefinitely.
A timeout limits how long a caller waits, but it does not reveal whether the remote operation happened.
That second point is where much of the real design work begins.
A concrete example: calculating shipping
Checkout asks a shipping provider for delivery options.
Most replies arrive within 300 milliseconds, but one request receives no answer. If checkout waits forever:
- the browser remains stuck,
- a server connection stays occupied,
- memory and request capacity remain reserved,
- and enough stuck calls can exhaust the service.
Checkout instead stops waiting after a defined deadline and offers a fallback or a retryable error.
Why waiting forever is dangerous
Every active call consumes something:
- a socket,
- a thread or asynchronous task,
- memory,
- a database connection,
- a queue slot,
- and part of the user's patience.
When a dependency slows, unlimited waiting lets congestion spread upstream. A timeout creates a boundary that contains some of that damage.
A timeout is not proof of failure
Suppose a payment request times out after two seconds.
The payment service may have:
- never received it,
- rejected it,
- completed the charge,
- still be processing,
- or completed it while the response was lost.
The caller only knows that a satisfactory response did not arrive before its deadline.
Connection timeouts
A connection timeout limits how long establishing a network connection may take.
This stage can include:
- DNS resolution,
- opening a TCP connection,
- negotiating TLS,
- and acquiring a connection from a local pool.
If connection setup consumes the whole user deadline, no time remains for the actual request.
Request and response timeouts
After connection, a client may apply limits to:
- sending the request,
- waiting for response headers,
- reading each response segment,
- or completing the entire operation.
A per-read timeout that resets whenever one byte arrives can allow a response to continue indefinitely. An overall deadline protects the complete user operation.
Deadlines versus durations
A timeout duration says, "Wait up to two seconds from now."
A deadline says, "This work must finish by 10:15:03.400." Deadlines are easier to propagate through a call chain because each service can calculate the time still available.
Without propagation, three services may each wait five seconds and turn one five-second user expectation into fifteen seconds or more.
Timeout budgets
An overall operation has a latency budget.
For a two-second checkout calculation, the budget might reserve:
- 200 milliseconds for routing and local work,
- 800 milliseconds for inventory,
- 600 milliseconds for shipping,
- and 400 milliseconds for response and safety margin.
The exact numbers come from observed distributions and product needs, not arbitrary round values.
Choosing a timeout
A useful timeout balances two errors:
- too short: abandon healthy but slower operations,
- too long: hold resources and users during real failure.
Use:
- measured latency percentiles,
- business deadlines,
- downstream service objectives,
- retry budget,
- network geography,
- and resource capacity.
One timeout value rarely fits every endpoint and operation.
Tail latency
Most requests can be quick while a small fraction are dramatically slower.
Those slow requests form the tail of the latency distribution. A timeout based only on average latency may cut off many legitimate requests or wait far too long.
Look at p95, p99, and failure distributions alongside the median.
Timeout propagation
When service A calls B, and B calls C, the remaining deadline should travel downstream.
If A has 400 milliseconds left, B should not start a call to C with a fresh five-second timeout. B should either use the remaining budget or decline work that cannot finish meaningfully.
Deadline propagation prevents abandoned upstream requests from creating useless downstream load.
Cancellation
A timeout ends the caller's wait. Cancellation attempts to stop the underlying work.
Cancellation may fail because:
- the server already committed the action,
- the protocol does not support cancellation,
- the cancellation message is delayed,
- or another worker now owns the task.
Code should not assume that closing a client connection reverses a remote side effect.
Retrying after timeout
A retry may recover from a lost request or temporary delay, but it can repeat an operation that already succeeded.
Safe retries need:
- idempotent behavior,
- an idempotency key,
- bounded attempts,
- backoff and jitter,
- and enough remaining deadline.
Retrying a payment blindly after timeout can create two charges.
Fallback behavior
Some timed-out operations can degrade gracefully.
Examples:
- show cached recommendations,
- omit a nonessential widget,
- use a default shipping estimate,
- accept work for later processing,
- or explain that a result is still pending.
A fallback must be safe for the business rule. A stale bank balance is not equivalent to a stale weather forecast.
Timeouts and circuit breakers
When many calls to one dependency time out, continuing to send full traffic can worsen overload.
A circuit breaker temporarily rejects or redirects calls after a failure threshold, then probes for recovery. Timeouts detect individual waits; circuit breakers limit repeated demand on a failing path.
They need careful thresholds so brief ordinary variation does not disable a healthy service.
Queueing time
Timeout measurement should include time waiting before work starts.
A request can spend most of its deadline:
- waiting for a thread,
- waiting for a connection pool,
- waiting in a load balancer,
- or waiting in a server queue.
Measuring only handler execution hides user-visible delay.
Observability
Record:
- which operation timed out,
- timeout stage,
- configured limit,
- elapsed time,
- remaining upstream deadline,
- dependency name,
- and correlation identifier.
Metrics should distinguish connection failure, timeout, cancellation, and explicit remote errors. Grouping all of them as "request failed" makes tuning difficult.
Testing timeout behavior
Tests should intentionally simulate:
- delayed connection,
- slow response headers,
- stalled body,
- response just before the deadline,
- response just after it,
- cancellation,
- and a side effect completed despite client timeout.
The boundary cases reveal races that happy-path tests miss.
User feedback
A timeout is a system event, but the product must translate it into understandable feedback.
Depending on the operation:
- "Shipping options are temporarily unavailable."
- "Payment status is being confirmed; do not submit again."
- "The report is taking longer than expected. We will notify you."
The message should guide the next safe action rather than expose an internal exception.
A practical timeout checklist
For each remote call, ask:
- What is the total user or job deadline?
- Which connection and response stages need limits?
- How much budget remains for retries?
- Can the remote side effect outlive the caller?
- Is repetition safe?
- Is a fallback valid?
- How will operators distinguish timeout causes?
Knowledge check
- Why does a timeout not prove that a remote operation failed?
- How does an overall deadline differ from a per-read timeout?
- Why should deadlines propagate through service calls?
- What is the difference between timeout and cancellation?
- Which evidence should guide timeout selection?
The one idea to remember
Every remote call needs a deliberate waiting limit based on business deadlines and observed latency. A timeout releases the caller from waiting, but the remote result may remain uncertain, so retries, idempotency, cancellation, fallback, and user feedback must be designed together.