Quick revision
The short answer
The connection timeout limits how long we wait to establish the TCP connection and TLS handshake; the read timeout limits how long we wait for data on an open connection, between reads, so it does not bound the total time if data trickles in; and an overall deadline bounds the whole call, including retries. A RestTemplate or RestClient created without timeouts uses the underlying client's defaults, which for many clients means waiting indefinitely or for minutes, so one slow dependency can hold every request thread. We set timeouts through the request factory or client builder, and recent Spring Boot versions also offer HTTP client settings properties, so check your version.
What to remember
In this answer, we saw that the connection timeout covers establishing the TCP and TLS connection, the read timeout limits silence on an open connection and resets with every chunk, so it does not bound the total time, and an overall deadline bounds the whole call including retries. Without timeouts, RestTemplate and many RestClient backends wait indefinitely or for minutes, and one slow dependency can occupy every request thread, so we set timeouts on the request factory or builder, with Boot's client properties as a default.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The connection timeout limits how long we wait to establish the TCP connection and TLS handshake; the read timeout limits how long we wait for data on an open connection, between reads, so it does not bound the total time if data trickles in; and an overall deadline bounds the whole call, including retries. A RestTemplate or RestClient created without timeouts uses the underlying client's defaults, which for many clients means waiting indefinitely or for minutes, so one slow dependency can hold every request thread. We set timeouts through the request factory or client builder, and recent Spring Boot versions also offer HTTP client settings properties, so check your version.
Why this question is asked
Timeouts are the cheapest resilience feature and the one most often missing. A service without them works perfectly until a dependency becomes slow, and then it stops answering everything, not just the calls to that dependency. Interviewers ask this to see whether we know which timeout covers which part of a call and what really happens without them. In this answer, we will recap the stages of an HTTP call, define each timeout against those stages, see why a read timeout is not a total limit, reproduce the thread exhaustion that missing timeouts cause, and set the timeouts properly in Spring Boot.
1A Quick Recap of the Stages of an HTTP Call
When our service calls another one over HTTP, several things happen in order. First the client opens a TCP connection to the server, a short exchange of packets that takes one network round trip. If it is HTTPS, a TLS handshake follows, which takes one or two more round trips. Then the client writes the request. Then it waits for the server to process the request and start sending the response, and finally it reads the response, which may arrive in several chunks.
Each timeout covers a different part of this sequence, which is why there is more than one. With pooled connections, there is also a step before all of these: borrowing a connection from the pool, which has its own timeout, but here we focus on the three the question names.
| Stage | Covered by | Typical value |
|---|---|---|
| Open TCP connection, TLS handshake | connection timeout | 500 ms to 2 s |
| Wait for first byte of the response | read timeout | based on dependency p99 |
| Each gap between chunks of the body | read timeout (per read) | same value |
| The whole call, including retries | overall deadline | the caller's budget |
2Connection Timeout and Read Timeout
The connection timeout limits how long the client waits for the connection to be established. If the server's host is down or a firewall silently drops packets, a connection attempt can hang for a long time, often over a minute with operating system defaults. A connection timeout of one or two seconds turns that into a quick, clear failure. Because connecting normally takes a few milliseconds inside a data centre, a short value is safe.
The read timeout, also called socket timeout, limits how long the client waits for data on an open connection. It starts when the client begins waiting and resets every time some data arrives. So it is really a limit on silence: no byte for longer than the timeout means failure.
But there is a catch. Because the read timeout resets with every chunk, it does not limit the total time. A server that sends one byte every 4 seconds will never trigger a 5 second read timeout, even if the full response takes ten minutes. Slow, trickling responses happen with overloaded servers, bad proxies and large streamed bodies.
3The Overall Deadline
An overall deadline limits the whole call from start to finish, however the time is spent: borrowing a connection, connecting, waiting, reading and any retries. It is the only setting that matches what the user cares about, such as the page must answer within 2 seconds. Some clients offer it directly, such as the JDK HttpClient's request timeout, which limits the time until the response headers arrive (check the client's documentation for exactly what it covers). Otherwise we apply it around the call, for example with Resilience4j's TimeLimiter, or with a reactive client's timeout operator, which cancels the request when the time is up.
When retries are involved, the deadline matters even more. Three attempts with a 2 second read timeout each, plus backoff, can take over 6 seconds. A deadline of 2.5 seconds around the whole thing guarantees the caller an answer, success or failure, in time.
4What Happens Without Timeouts
Without explicit settings, RestTemplate's default request factory uses Java's HttpURLConnection with timeouts of zero, which means wait forever. RestClient picks an underlying library from the classpath, such as Apache HttpClient, Jetty, Reactor Netty or the JDK client, and each has its own defaults, often no response timeout at all or several minutes for some stages. Check the defaults of whichever library you use, but assume they are not safe.
Now picture a Spring MVC service with 200 request threads, the Tomcat default. Each incoming request that calls a slow dependency holds its thread while it waits. If the dependency stops answering and 50 requests per second need it, all 200 threads are stuck within 4 seconds. From then on the service cannot answer anything, including health checks and requests that never touch the slow dependency. One slow dependency has taken the whole service down, and its callers may follow.
- Dependency becomes slowstops answering
- Each call waits foreverno read timeout
- Request threads pile up50 per second x seconds of waiting
- All 200 threads busyafter about 4 s
- Service answers nothinghealth checks fail too
- Callers wait on this servicethe failure moves upstream
6 steps in order. Play them, or step through them one at a time.
5Setting Timeouts in Spring Boot
The most direct way is to give the client a configured request factory. Here is a RestClient with explicit timeouts, which also works for RestTemplate through its constructor.
The property-based defaults are a good safety net, so a client nobody configured still has limits. Per-client values are still worth setting, based on each dependency's normal latency: a lookup with a p99 of 80 ms does not need a 2 second read timeout. And on top of both, an overall deadline for the call protects against trickling responses and retry loops.
6Follow-up questions
Why not just use a very short read timeout everywhere?
Because legitimate slow responses then fail, and retries make it worse by adding load. The read timeout should sit above the dependency's normal slow responses, for example its p99 or p99.9 plus a margin, and within the caller's own deadline.
Do reactive WebClient calls need timeouts too?
Yes. They do not hold threads while waiting, but without timeouts they hold connections, memory and the caller's request indefinitely. Reactor Netty offers connect and response timeouts on the HttpClient, and the timeout operator on the Mono bounds the whole call.
What about the timeout to get a connection from the pool?
That is a fourth timeout, the connection request or acquire timeout. If the pool is exhausted, threads wait there before any connect or read timeout starts, so it must be set as well; it is a common gap even in services that set the other two.
7Conclusion
In this answer, we saw that the connection timeout covers establishing the TCP and TLS connection, the read timeout limits silence on an open connection and resets with every chunk, so it does not bound the total time, and an overall deadline bounds the whole call including retries. Without timeouts, RestTemplate and many RestClient backends wait indefinitely or for minutes, and one slow dependency can occupy every request thread, so we set timeouts on the request factory or builder, with Boot's client properties as a default.
Open with
There are three different limits. The connection timeout covers establishing the connection, the TCP handshake and TLS, so if a host is down or packets are dropped we fail in a second or so instead of a minute.
Then, if they want more
The read timeout, or socket timeout, covers waiting for data on an open connection: it restarts every time bytes arrive, so it is really a limit on silence. That is the catch: it does not limit total time. A server trickling a byte every 4 seconds never trips a 5 second read timeout, even if the response takes minutes.
The overall deadline is the limit on the whole call, including connection, reading and any retries, and it is what matches the user's expectation; I apply it with a client feature like the JDK HttpClient's request timeout, or around the call with something like Resilience4j's TimeLimiter or a reactive timeout operator.
Without any settings, RestTemplate's default HttpURLConnection factory waits forever, and the libraries behind RestClient often have no response timeout or very long ones. Then a slow dependency holds a Tomcat thread per request; with 200 threads and 50 requests per second, everything is stuck in about 4 seconds, and the whole service, including its health checks, stops answering.
So I always set a short connect timeout and a read timeout based on the dependency's p99 on the request factory or client builder, use Boot's HTTP client properties as a default safety net where the version supports them, and add an overall deadline on top.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Cloud documentation, Resilience4j documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Explain connection timeout, read (response) timeout and an overall request deadline for...": https://scrivio-interview-library.netlify.app/spring-boot/resilience/a862554175/