Should we move our Spring Boot services from WebFlux or thread pools to virtual threads? What risks do you check?

Short answer

For I/O-bound request/response services on Java 21+, virtual threads give high concurrency with simple blocking code. Check pinning (largely fixed for synchronized in Java 24+), ThreadLocal usage, connection pool and downstream limits, library compatibility, and measure under load. Keep reactive where streaming and backpressure are central.

Detailed answer

  1. Fit: services mostly waiting on databases/HTTP benefit; CPU-bound services do not.
  2. Enable: spring.threads.virtual.enabled=true (Boot 3.2+); blocking JDBC and RestClient work naturally.
  3. Risks:
    • Pinning in synchronized blocks on Java 21–23 (JFR jdk.VirtualThreadPinned); upgrade to 24+/25 or replace with ReentrantLock.
    • Unlimited concurrency overwhelms databases: bound with HikariCP and semaphores.
    • Heavy ThreadLocal caches per thread multiply memory.
    • Libraries with native blocking or their own thread assumptions.
  4. Measure: throughput, p99 latency, memory, DB connection wait time before/after.
  5. WebFlux codebases: migrate only if complexity is costing you; reactive is still good for streaming.

What the interviewer expects

Nuance about benefits and limits, operational checks, and measurement.

Common mistakes to avoid

Claiming virtual threads make everything faster; pooling virtual threads; ignoring downstream limits.