I recently had the chance to work with Spring Cloud API, and I had trouble deciding between Spring MVC and WebFlux. So I’m sharing some of my research for anyone who’s either facing the same decision, wants some insight into what I discovered, or wants to share their input.
Initially, I wanted to go with WebFlux because every blog I read and everyone I talked to was talking about its non-blocking I/O. For people who aren’t familiar with reactive libraries, here’s how I looked at it.
Imagine creating a REST API that calls a database or an external service. Usually, you have to wait for the response before doing anything else, which is called a synchronous action. With reactive libraries, instead of just waiting, the application can perform another action, which we call an asynchronous action. Because you are not waiting for a response, you can do much more with fewer resources, but it has its cons, like being difficult to debug and having a steep learning curve.
And honestly, Jotty John does a better job going into detail, so I’ll leave the link below for anyone interested in learning more about WebFlux: https://dev.to/jottyjohn/spring-mvc-vs-spring-webflux-choosing-the-right-framework-for-your-project-4cd2
The question that I couldn’t seem to find a clear answer to on the internet, or wasn’t convinced enough by, was the following: if anyone is familiar with Java 21 and above, there is something called virtual threading, which addresses many of the same scalability problems that reactive libraries were designed to solve.
Because of that, choosing Spring MVC felt like a no-brainer since it has a bigger community and better tooling. And even though some industries or companies are migrating to reactive libraries, most of the code out there still uses MVC.
With all that, I became more interested than ever in why people choose Spring WebFlux over Spring MVC, and why no one was really talking about other alternatives like virtual threading, for example. The more I went deeper into the research, I started to realize things like backpressure and more.
So this is my takeaway: even though I could have built this with Spring MVC, I chose WebFlux because there are a lot of important tools already baked into it by talented engineers. I didn’t really feel like reinventing the wheel, at least not yet. I wanted this post to sound like me, not just another AI post, because I really want to hear people’s thoughts about the topic, even though it’s not the most popular topic out there. And I’m really sorry in advance for any grammar or syntax — blame my English teacher.
Top comments (0)