Home  >  Forum  >  Spring
Post New Query

Spring MVC vs WebFlux



Asked on September 04, 2020
What is difference between Spring MVC and WebFlux ?


Replied on September 05, 2020

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.




 




Replied on September 06, 2020
Difference in Concurrency Model

In Spring MVC (Servlet application), application can block the current thread for the reasons such as remote call. To accomplish the application performance, large thread pool is created so that other requests can be served.

In Spring WebFlux (in non-blocking servers), applications do not block, and hence they use a small, fixed-size thread pool to handle requests.   



Write Answer








©2020 concretepage.com | Privacy Policy | Contact Us