Search code examples
springspring-bootkotlinspring-mvcspring-webflux

Spring Boot - Web vs Webflux for RESTAPI


I am trying to decide whether to use Spring Web or Webflux for a RESTAPI.

I have done my research and read from a lot of developers on forums that Webflux is not so great because how difficult it is to code and debug and can even be slower than Web in some cases.

However, official documents and some articles say that Webflux is supposed to use system resources a lot better and more efficiently.

Also, some people say DB drivers (R2DBC) can be pretty buggy on Webflux.

So, these are my questions:

  1. Currently, is Webflux still buggy?
  2. Is coding (using Kotlin) on Webflux actually very different from Web? I use Kotlin and have done some demo projects and both Web and Webflux seem very similar to me.
  3. Currently, is debugging on Webflux still so difficult? If so, and thinking in the long run, would you NOT use Webflux because of this?
  4. Is Webflux a direct improvement/upgrade from Web? If not, can you tell me why? In what cases would you use Web instead of Webflux, given that Webflux uses resources more efficiently?
  5. Does Virtual Thread from Java 21 make Web a better choice than Webflux? I read that Virtual Thread would be a "gamechanger" to Web. Is this true?

Thank you for your helping me clarify this!😁


Solution

    1. Currently, is Webflux still buggy? No, webflux is reactive approach of programming. It may be hard to understand for people who has more experience on old MVC way.
    2. Is coding (using Kotlin) on Webflux actually very different from Web? I use Kotlin and have done some demo projects and both Web and Webflux seem very similar to me. It is similar from coding side but run flow of the code is different. Meaning catching responses from DB or any othor call works little bit different then regular older ways.
    3. Currently, is debugging on Webflux still so difficult? No If so, and thinking in the long run, would you NOT use Webflux because of this? Webflux may require more fine tuning on threads but after all it is same thing in different approach, if you are willing to do that way, go for it because webflux mature enough, you can learn and share.
    4. Is Webflux a direct improvement/upgrade from Web? No If not, can you tell me why? Because there is no proof I have seen so far it is better than non reactive approach. In what cases would you use Web instead of Webflux, given that Webflux uses resources more efficiently? Mostly I would use Web instead of webflux, then if I am having heavy load I would do A/B tests and compare performance which can be affected from DB design to netwrok, webflux mainly promise better performance on heavy load, but without testing throughly I would not believe it and it changes every application and DB
    5. Does Virtual Thread from Java 21 make Web a better choice than Webflux? Maybe I read that Virtual Thread would be a "gamechanger" to Web. Is this true? They look shiny but I am not sure it will bring soo much for webflux, check here.

    I have been testing webflux for a long time, I see webflux has better numbers than spring web(sometimes-check different tests on the page), but my test is only depends on json serialization, if we put in DB layer all numbers would change, app to app and design to design we should to tests and decide after.