Question
What happens if you call a blocking DB method inside a reactive WebFlux endpoint?
A. It works fine
B. Non-blocking benefit is lost
C. Reactor detects and throws an error
D. App crashes
Answer
B. Non-blocking benefit is lost
Why?
If we call a blocking method (ex., JDBC call) inside a reactive webflux endpoint, the call will block the event-loop thread that is supposed to handle many requests concurrently.
It still works because the blocking call returns eventually. So the request completes.
But the scalability benefit of WebFlux is gone, since that thread is occupied and can’t process other requests while waiting.
The reactor doesn’t automatically detect or throw an error. It just runs the blocking call on the event loop.
The app doesn’t crash, but under the load, performance can degrade severely.
Best Practice
If we must call a blocking call a blocking API, we should wrap it boundedElastic Scheduler.
Mono.fromCallable(() -> repository.findById(id))
.subscribeOn(Schedulers.boundedElastic());
This way, blocking work runs on a dedicated thread pool, and the event-loop remains non-blocking.