Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

Explain connection timeout, read (response) timeout and an overall request deadline for an HTTP client in a Spring Boot service. What happens if a RestTemplate or RestClient is created without timeouts?

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.

Which timeout covers which stage
StageCovered byTypical value
Open TCP connection, TLS handshakeconnection timeout500 ms to 2 s
Wait for first byte of the responseread timeoutbased on dependency p99
Each gap between chunks of the bodyread timeout (per read)same value
The whole call, including retriesoverall deadlinethe 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.

Java
// read timeout = 5 s
// server sends headers after 1 s, then one chunk every 4 s for 40 chunks
// gaps: 1 s, 4 s, 4 s, ... all below 5 s -> no read timeout
// total time for the call: about 161 s

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.

Step throughHow a missing timeout spreads
  1. Dependency becomes slowstops answering
  2. Each call waits foreverno read timeout
  3. Request threads pile up50 per second x seconds of waiting
  4. All 200 threads busyafter about 4 s
  5. Service answers nothinghealth checks fail too
  6. 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.

Java
@Bean
RestClient paymentsClient(RestClient.Builder builder) {
var factory = new SimpleClientHttpRequestFactory(); // or a JDK, Apache or Jetty factory
factory.setConnectTimeout(Duration.ofSeconds(1));
factory.setReadTimeout(Duration.ofSeconds(2));
return builder.baseUrl("http://payments").requestFactory(factory).build();
}
// payments host unreachable -> ResourceAccessException after about 1 s (connect timed out)
// payments silent for 2 s -> ResourceAccessException after about 2 s (read timed out)
# Recent Spring Boot versions can set defaults for auto-configured clients,
# for example (Boot 3.4 and later; names changed again in Boot 4, check your version):
spring.http.client.connect-timeout=1s
spring.http.client.read-timeout=2s

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.

What to say in the interviewAbout 100 seconds aloud

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.
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/