Spring MVC vs WebFlux


1. The common between Spring MVC or WebFlux are @Controller,
Reactive clients. Both can run on the servers such as Tomcat, Jetty, Undertow.
2. In Spring MVC we can have imperative logic, JDBC, JPA. In
Spring WebFlux we can have functional endpoints, event loop, concurrency model.
Spring WebFlux can run on Netty server.
When to Use Spring MVC or WebFlux
1. If we have already a working Spring MVC application, it
is not needed to convert into Spring WebFlux. Spring MVC uses imperative
programming that is easy way to write and debug.
2. If we want to create a non-blocking web stack, we can
choose Spring WebFlux that provides choice of servers (Netty, Tomcat, Jetty,
Undertow, and Servlet 3.1+ containers), a choice of programming models
(annotated controllers and functional web endpoints), and a choice of reactive
libraries (Reactor, RxJava, or other).
3. Spring WebFlux is useful for lightweight, functional web
framework using with Java 8 lambdas or Kotlin.
4. In microservice application we can have a mix of
applications of Spring MVC and Spring WebFlux controllers. We can also have
Spring WebFlux endpoints.
5. If our application is depending on JPA, JDBC or
networking APIs to use, Spring MVC is the best choice.
6. If our application calls to remote services, we can try
reactive WebClient.

