Module 11 · Executable guide

WebFlux vs Vert.x vs Virtual Threads

So sánh abstraction, threading, backpressure, architecture và decision trade-offs.


1. Async abstraction

ConceptCompletableFutureReactorVert.x
Single async valueCompletableFuture<T>Mono<T>Future<T>
TransformthenApplymapmap
Async chainthenComposeflatMapcompose
RecoverexceptionallyonErrorResumerecover
Multi-valueKhông phải abstraction chínhFlux<T>ReadStream/EventBus/API riêng

2. Threading

ModelMindset
Spring MVC + Virtual ThreadsImperative blocking code, nhiều lightweight threads.
WebFluxReactive chain + event-loop/non-blocking I/O.
Vert.xEvent-loop + Future/Event Bus.

3. Backpressure

WebFlux/Reactor đặt Reactive Streams ở trung tâm. Vert.x có flow-control ở nhiều stream APIs nhưng Future/EventBus không đồng nghĩa Reactive Streams.

4. Architecture

Spring WebFlux: Controller → Service → Reactor → R2DBC/WebClient
Vert.x:         Router → Verticle/Service → Future/EventBus → SQL/WebClient

5. Complexity

  • Reactive chains cần operator literacy và debugging tốt.
  • Vert.x cần kỷ luật event-loop và explicit architecture.
  • Virtual Threads làm imperative blocking style cạnh tranh hơn cho nhiều I/O workloads.

6. Decision matrix

Tình huốngCân nhắc
Team Spring mạnh, downstream non-blockingWebFlux.
CRUD blocking, ưu tiên simplicityMVC + Virtual Threads.
Event-driven toolkit, EventBus/Verticle phù hợpVert.x.
Reactive Streams end-to-endWebFlux/Reactor tự nhiên hơn.
Legacy blocking SDK nhiềuVirtual Threads hoặc bounded bridge; tránh “reactive giả”.