Core principles of Spring WebFlux
- Asynchronous operations: All I/O operations like database access, network calls etc are asynchronous and non-blocking. This prevents threads from blocking on I/O.
- Reactive streams: Data is processed and consumed asynchronously as streams of multiple values over time rather than single blocking responses.
- Reactive Streams compliance: WebFlux is built on Project Reactor which implements Reactive Streams. This allows asynchronous and non-blocking processing of data streams.
- Non-blocking requests: The underlying server (Netty by default) is fully asynchronous and non-blocking. It can handle many more requests concurrently without blocking threads.
Basic Introduction to Spring WebFlux
Spring WebFlux is a reactive, non-blocking web framework that uses Project Reactor’s reactive streams API to enable highly concurrent and asynchronous processing of web requests in a non-blocking and event-driven way. It is fully asynchronous and non-blocking using reactive streams and callbacks.
- It uses Project Reactor as the underlying reactive library for composable asynchronous and event-based programming.
- The core abstraction is around reactive streams – publishers that provide push-based asynchronous streams of data.
- Controllers return Publisher or Mono types instead of ModelAndView. Responses are streamed back incrementally.
- It is optimized for non-blocking and event-driven applications on modern servers like Netty and Undertow.
In this article, we will explore the advantages and disadvantages of Spring WebFlux – a non-blocking web framework.