Return to site

⚡🧵 WEBFLUX/NETTY VS VIRTUAL THREADS/TOMCAT IN SPRING BOOT (REAL-WORLD CHOICE)

· spring,java,loom,architecture,techlead

🔸 TLDR

▪️ WebFlux + Netty = non-blocking I/O on a small event-loop thread set (great for streaming + massive concurrent I/O).

▪️ Spring MVC + Virtual Threads + Tomcat = blocking code stays simple, but concurrency scales better because threads are cheap (Java 21+).

▪️ For most CRUD apps with JPA/JDBC/legacy SDKs, MVC + virtual threads is often the pragmatic default today.

Section image

🔸 THE CORE “VERSUS” (MENTAL MODEL)

▪️ WebFlux/Netty: “Don’t block. Ever.” ➜ you win when everything is reactive end-to-end (client ↔ server ↔ DB).

▪️ Virtual threads/Tomcat: “Blocking is OK.” ➜ you win when your dependencies are blocking (JDBC, SDKs, filesystem) but you still need high concurrency.

🔸 WHAT SPRING BOOT ACTUALLY DOES

▪️ Virtual threads require Java 21+ and are enabled via: spring.threads.virtual.enabled=true (Boot docs also mention Java 24+ recommended for best experience).

▪️ WebFlux can run on Netty/Tomcat/Jetty/Undertow, but Netty is the common default for reactive apps.

▪️ Reactor Netty uses an Event Loop Group sized ~CPU cores (minimum 4) by default.

🔸 CODE SNIPPET: SPRING MVC + TOMCAT + VIRTUAL THREADS

# application.properties

spring.threads.virtual.enabled=true

🔸 CODE SNIPPET: WEBFLUX + NETTY (NON-BLOCKING ALL THE WAY)

@RestController

▪️ WebFlux + accidental blocking (JPA/JDBC, “just one” SDK call, block()) can silently push work to other schedulers and kill the “event-loop advantage”.

▪️ Virtual threads ≠ faster CPU: they shine when you wait on I/O, not when you’re CPU-bound.

▪️ Deployed on external Tomcat (WAR): your container may keep using its own thread pool, so don’t assume Boot’s virtual-thread setting applies the same way.

🔸 QUICK PICK GUIDE

▪️ Choose MVC + Virtual Threads + Tomcat when:

▪️ You use JPA/JDBC, blocking clients, or lots of “normal enterprise” libs

▪️ You want simple debugging + familiar stack

▪️ You need better concurrency without rewriting everything reactive

▪️ Choose WebFlux + Netty when:

▪️ You do streaming (SSE/WebSocket), fan-out calls, high concurrent connections

▪️ You can keep the chain reactive end-to-end (reactive DB, reactive clients)

▪️ You benefit from backpressure and non-blocking resource usage

🔸 TAKEAWAYS

▪️ Virtual threads reduce the main reason people used reactive: “threads are expensive.”

▪️ WebFlux still wins for true reactive pipelines + streaming/backpressure scenarios.

▪️ The best default for many teams in 2026: MVC + virtual threads, and reach for WebFlux when the use case demands it.

#SpringBoot #Spring #Java #VirtualThreads #ProjectLoom #SpringWebFlux #ReactorNetty #Tomcat #Netty #ReactiveProgramming #BackendEngineering #Microservices #PerformanceEngineering

Go further with Java certification:

Java👇

Spring👇

SpringBook👇

JavaBook👇