When I build a standard web API in the Java world, there are two ways to do it today.
- Use SpringMVC (non-reactive)
- Use SpringWebFlux (reactive)
There are few benefits of using Reagent that I can think
- Uses fewer memory resources, since there are fewer threads running (perhaps better for a container-based implementation)
- It is better for situations in which your api might need to call other apis and does not want to think about the concurrency problem (this can also be done in traditional webmvc, but then you need to use
CompletobleFuturo etc while in reagent let the framework handle it)
There are some disadvantages that occur to me when using Reagent
- The complexity of the code, since everything is now chained and you must be careful not to block the thread and you must be aware that there is no
ThreadLocal like things like registration using MDC is more complicated now
- Increase latency as there are fewer threads now
One of the selling points of the reactive way of doing things is the back pressure concept, but when the normal request / response is reached in the web pages, it is not used, whether you process it or not, there is not a process in the chain that reduces the production of data.
I'm not sure if the benefit I mentioned above is worth the complexity of a web apis. I would like to hear thoughts about that. If web pages are not the right place to use reagents, where do you think is the right place to use them? Or if the reactive form is the way to do it, then does not mean that there is no longer any place for the traditional way of doing things in the webmvc?