Skip to the page

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.

The 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.Builder so 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 @GetExchange and @PostExchange that Spring implements on top of RestClient or WebClient.
  • Always set connect and read timeouts. RestClient.create(restTemplate) helps migrate call by call. Test with @RestClientTest and MockRestServiceServer, 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 synchronized held the carrier thread. JEP 491 removed this for synchronized.
  • 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

  1. Which HTTP client would you use in Boot 4 and why?
  2. MVC on virtual threads or WebFlux for a notification service?
  3. What is an HTTP interface client?
  4. What new bottlenecks appear with virtual threads?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview