Spring REST APIs · senior
HTTP clients, virtual threads and WebFlux
Use RestClient or an HTTP interface for new calls. For I/O-bound services, MVC on virtual threads is usually simpler than WebFlux, but you must add your own limits.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- RestTemplate is deprecated in Framework 7.1 with removal planned for 8. Not for new code.
- RestClient: synchronous and fluent; the default for MVC apps. Build it from Boot's auto-configured
RestClient.Builderso it gets tracing and message converters. - WebClient: non-blocking, for WebFlux or streaming. Calling
.block()everywhere in an MVC app gives the cost of reactive code without the benefit. - HTTP interface: a Java interface with
@GetExchangeand@PostExchangethat Spring implements on top of RestClient or WebClient. - Always set connect and read timeouts.
RestClient.create(restTemplate)helps migrate call by call. Test with@RestClientTestandMockRestServiceServer, or WireMock. - Virtual threads are final since Java 21. In Boot 3.2 and later one property (
spring.threads.virtual.enabled=true) runs Tomcat requests on virtual threads. - Pinning: before Java 24, blocking inside
synchronizedheld the carrier thread. JEP 491 removed this forsynchronized. - New bottleneck: Tomcat's 200 threads no longer limit concurrency, so the HikariCP pool, partner rate limits and memory become the limits. WebFlux is still right for streaming (SSE, very many WebSockets), back-pressure and a fully reactive stack. The cost is harder code and debugging.
The red pen
Common traps: mistake → fix
Mistake: WebFlux is always faster
Fix: for blocking-style I/O work, MVC on virtual threads is simpler and often enough.
Mistake: Virtual threads remove all limits
Fix: the pool and partner limits remain.
Mistake: RestTemplate is fine for new code
Fix: it is deprecated.
Easy to hard
Questions interviewers ask, easy to hard
- Which HTTP client would you use in Boot 4 and why?
- MVC on virtual threads or WebFlux for a notification service?
- What is an HTTP interface client?
- What new bottlenecks appear with virtual threads?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.