Quick revision
The short answer
Without timeouts, a downstream service that hangs keeps our request threads and HTTP connections waiting, possibly for minutes, until the pool runs out and our own service stops answering. We set a connect timeout and a read timeout on the HTTP client behind RestClient, choose them so that they fit inside our own latency budget with time left for our work, remember that retries multiply the time spent, and monitor the client's latency percentiles and timeout counts.
What to remember
In this answer, we saw that a RestClient call without timeouts lets one hung downstream block our request threads and connections until our own service stops answering. We set a connect timeout and a read timeout on the underlying HTTP client, choose the read timeout from the downstream's latency so that it fits inside our own latency budget with room for our work, count every retry against that budget, and watch the client's percentiles and timeout counts to see trouble early.
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.
Without timeouts, a downstream service that hangs keeps our request threads and HTTP connections waiting, possibly for minutes, until the pool runs out and our own service stops answering. We set a connect timeout and a read timeout on the HTTP client behind RestClient, choose them so that they fit inside our own latency budget with time left for our work, remember that retries multiply the time spent, and monitor the client's latency percentiles and timeout counts.
Why this question is asked
Missing timeouts are one of the most common causes of cascading failures: one slow service makes its callers slow, and their callers slow, until a whole system stops. The code looks perfectly normal, which is why interviewers ask about it. In this answer, we will recap what connect and read timeouts are, see how a hung downstream exhausts our threads, configure timeouts on RestClient, connect them to a latency budget, look at what retries do to that budget and finish with what to monitor.
1A Quick Recap: Connect and Read Timeouts
A call over HTTP has two waiting phases. First the client opens a TCP connection to the server; the connect timeout limits how long we wait for that. Then it sends the request and waits for the response; the read timeout, sometimes called the response or socket timeout, limits how long we wait for data to arrive.
RestClient, Spring's synchronous HTTP client since Spring Framework 6.1, does not do the networking itself. It delegates to a ClientHttpRequestFactory that wraps a real HTTP library, such as the JDK's HttpClient, Apache HttpClient or Jetty. The timeouts live in that underlying client, and depending on the library and version the default is either no limit at all or a value in minutes. Either is far too long for a request a user is waiting on.
2How a Hung Downstream Exhausts Our Threads
Suppose our service runs on Tomcat with 200 request threads and calls a pricing service for every request. Pricing has a problem and accepts connections but never answers. Each incoming request now blocks on the pricing call and holds its thread.
At 100 requests per second, all 200 threads are stuck within two seconds. New requests queue, then time out at the load balancer, and our health checks may fail too, so the orchestrator restarts pods that are not actually broken. Requests that do not even need pricing fail as well, because there is no thread left to serve them. The failure of one dependency has become a failure of our whole service.
7 messages in order. Play them, or step through them one at a time.
Without a timeout, the wait has no end, and every request that touches pricing holds a thread.
3Setting Timeouts on RestClient
We give RestClient a request factory whose client has both timeouts. With the JDK's HttpClient it looks like this.
Notice the two different numbers. Connecting inside a data centre takes about a millisecond, so a few hundred milliseconds is generous, and a failed connect should fail quickly. The read timeout depends on how long the downstream normally takes. A good rule is a little above its p99, the time 99 percent of calls finish within, so that only truly stuck calls are cut off.
Spring Boot can also apply timeouts through its HTTP client settings, either as properties or with ClientHttpRequestFactorySettings and the builder Boot provides. The property names changed between Boot 3.x and 4.0, so check your version; the important thing is that every client has both timeouts, explicitly.
4Fitting Timeouts Into a Latency Budget
A latency budget is the time a request may take, usually taken from a service level objective such as 'p99 under 1 second'. Every step inside the request spends part of it. If we promise our callers 1,000 ms and a downstream call may take 800 ms, we have only 200 ms for our own work, the database and building the response, and no margin at all.
So the timeout is not chosen in isolation. We write the budget down: 1,000 ms total, 150 ms for our own work and database, a 150 ms margin, which leaves 700 ms for the pricing call. If the pricing p99 is 400 ms, a 600 ms read timeout fits. If its p99 is 900 ms, no timeout will make the budget work, and we need a cache, an asynchronous design or a conversation with the pricing team.
5Retries Multiply the Time
Retries are often added at the same time as timeouts, and they spend the budget again. With a 600 ms timeout and two retries, the worst case is three attempts, 1,800 ms, plus any backoff between them, which is far beyond our 1,000 ms promise.
So the rule is that all attempts together must fit in the budget. In practice that means at most one retry with a shorter timeout, only for idempotent calls, the ones that are safe to repeat such as a GET, and only for errors that a retry can fix, such as a connection reset. Retrying a timeout against an overloaded service often makes the overload worse.
6What to Monitor
Timeouts are only safe if we can see them. With Spring Boot Actuator and Micrometer, RestClient built from Boot's builder records an http.client.requests timer per URI template and outcome. We chart the client's p50, p95 and p99 latency next to the timeout value and count the timeouts. A p99 that creeps towards the timeout tells us the downstream is slowing before users notice, and a rising timeout count tells us our fallback path is carrying real traffic.
7Follow-up questions
Should the connect timeout and the read timeout be the same?
Usually not. Connecting inside a network is fast and a failure to connect usually means the host is down, so a short connect timeout, a few hundred milliseconds, fails fast. The read timeout depends on the work the downstream does and should be set from its measured latency, a little above its p99.
Is a circuit breaker a replacement for timeouts?
No, they work together. The timeout limits how long one call can take. A circuit breaker, for example from Resilience4j, watches many calls and, when too many fail or time out, stops calling the downstream for a while and fails fast. Without timeouts the breaker never sees failures from a hung service, because the calls simply never finish.
Do virtual threads make timeouts unnecessary?
No. Virtual threads make blocked threads cheap, so we may not run out of threads, but each waiting request still holds memory, an HTTP connection from the client's pool and possibly a database connection, and the user is still waiting. Timeouts protect the latency promise and the other resources, not only the threads.
8Conclusion
In this answer, we saw that a RestClient call without timeouts lets one hung downstream block our request threads and connections until our own service stops answering. We set a connect timeout and a read timeout on the underlying HTTP client, choose the read timeout from the downstream's latency so that it fits inside our own latency budget with room for our work, count every retry against that budget, and watch the client's percentiles and timeout counts to see trouble early.
Open with
Without timeouts, if the downstream accepts the connection and then hangs, each request thread waits indefinitely, or for minutes depending on the HTTP library's default. With 200 Tomcat threads at 100 requests per second, everything is blocked within seconds, and even requests that do not need that dependency fail.
Then, if they want more
So I always set two timeouts on the client behind RestClient: a short connect timeout, a few hundred milliseconds, and a read timeout a little above the downstream's p99. I configure them on the request factory, for example the JDK client with JdkClientHttpRequestFactory, or through Spring Boot's HTTP client settings. Then I check them against my latency budget.
If I promise a p99 of one second, the downstream call plus my own work plus a margin must fit inside that second. Retries count too: the total of all attempts must fit, so at most one retry, only for idempotent calls. On timeout I catch the exception and degrade if I can.
Finally I monitor http.client.requests percentiles and timeout counts, so I can see the downstream slowing down before it reaches the timeout.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Framework 6
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. 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 "A Spring Boot service calls another service with RestClient and has no timeouts...": https://scrivio-interview-library.netlify.app/spring-boot/service-performance/c0bcbd7771/