Say Hello to Spring WebFlux
Explore how to build reactive web applications using Spring WebFlux with Spring Boot. Understand the differences between Spring MVC and WebFlux, and how reactive programming enables scalable, non-blocking web services using Netty server.
We'll cover the following...
Web applications dominate the landscape. When it comes to building web applications, the most popular toolkit has been Spring MVC.
That is, until Spring Framework 5.0.
With new startups embracing potentially millions of users, it has become imperative to scale the web layer. When our needs grow huge, using Spring WebFlux to reactively serve web requests is the way to go.
Note: S Spring Framework is the core toolkit underlying Spring Boot. It has become arguably the most popular toolkit in the Java community. Spring Framework 5.0 has embraced Reactive Streams through Project Reactor, and much of what this course covers involves Spring Boot’s strong synergy with the Spring Framework.
While Spring Framework 5.0 introduced reactive-based programming, this course—which is based on Spring Boot 2.7—uses Spring Framework 5.3.
So, what’s the big difference between Spring WebFlux and Spring MVC?
Spring WebFlux vs Spring MVC
Spring MVC is built atop Java’s well-honed servlet API. There are many assumptions in its underlying contracts. The biggest one is that the servlet API is blocking. There’s some asynchronous support since Servlet 3.1, but it’s not completely reactive. It doesn’t come with support for fully reactive event loops and backpressure signals.
Let’s say hello to Netty, a 100% non-blocking, asynchronous web container. It isn’t beholden to the servlet spec. Spring WebFlux and Netty work quite well together, while still using the same programming model that has made Spring MVC so popular.
The below Venn diagram below shows the similarities and differences between Spring WebFlux and Spring MVC: