From Coding to Cooking to Coins:
Antonio Lagnada's Blog on Software, Music, Food, and Finance

Spring WebFlux/Reactive • Frequently Asked Questions

Post Date: 17 Oct 2023


In the evolving landscape of web development, reactive programming has emerged as a game-changer, offering solutions to modern high-concurrency, low-latency demands. At the forefront of this shift in the Java ecosystem is Spring WebFlux, an innovative framework that champions the reactive paradigm.

As developers embark on this journey of asynchronous and non-blocking development, a plethora of questions arise. Whether you’re a seasoned developer adjusting to the reactive mindset or a newcomer curious about its capabilities, this article aims to address the most frequently asked questions about Spring WebFlux and the underlying principles of reactive programming. Let’s dive in and demystify the world of reactive Spring!

Is This Subject Generally Referred As “Spring Webflux” or “Spring Reactive”?

“Spring WebFlux” and “Spring Reactive” are terms related to the reactive programming support in the Spring ecosystem, but they are not synonymous.

Spring WebFlux

Spring Reactive

When discussing the web framework specifically, the term “Spring WebFlux” is appropriate. When discussing the broader reactive capabilities of the Spring ecosystem, “Spring’s reactive support” or “Spring Reactive” might be used, although the latter isn’t a formal name.

Is WebFlux Better Than The Traditional Spring WebMVC?

Spring WebFlux and traditional Spring MVC (often just called “Spring” in this context) serve different purposes, so it’s essential to understand their design goals and use cases to make a fair comparison.


Performance & Scalability

Use Cases

Development Complexity

Database Access

To sum it up, “performance” isn’t just about speed but also about scalability and responsiveness. In scenarios with high concurrency, Spring WebFlux can outperform Spring MVC due to its non-blocking nature. However, for applications with typical usage patterns and lower concurrency, traditional Spring MVC might be sufficient and could even be faster due to the overhead of reactive programming in WebFlux.

Always benchmark and test based on your specific use case to decide which approach is best for your application.

Does This Mean That The Web Container Can Be Tuned With Smaller Thread Counts?

Yes, exactly. With traditional web containers that support servlet-based web applications (like Tomcat in its default mode), a large number of threads is often provisioned to handle many simultaneous connections, especially if the operations performed are I/O bound and blocking.

However, in a non-blocking environment like that provided by Spring WebFlux:

  1. Threads Aren’t Blocked: In a reactive, non-blocking setup, a thread doesn’t wait idly for an operation to complete (like a database call). Instead, it’s returned to the thread pool to handle other tasks. This means a smaller number of threads can efficiently handle a larger number of concurrent connections.

  2. Netty: Spring WebFlux, by default, uses Netty as its runtime which is an asynchronous event-driven network application framework. Netty is designed to handle thousands of concurrent connections with a small number of threads.

  3. Thread Tuning: Given that threads aren’t blocked waiting for I/O operations, you can tune your reactive web container to operate with a much smaller thread count compared to traditional servlet containers. This can lead to a lower memory footprint and potentially better utilization of CPU resources.

  4. Back-Pressure: Reactive streams (which Spring WebFlux is built upon) also introduce the concept of back-pressure. This allows systems to signal upstream to slow down if they can’t handle the current load, providing another layer of efficiency and protection against resource exhaustion.

  5. Efficient Resource Use: One of the main benefits of the non-blocking model is the efficient use of resources. Instead of provisioning a large number of threads (which consume memory and other resources), you can operate efficiently with a smaller number, even under high concurrency scenarios.

However, while it sounds great (and often is, in the right scenarios), reactive programming and non-blocking architectures introduce complexity. It’s essential to understand this paradigm thoroughly, as debugging, reasoning about the flow, and handling exceptions can be more challenging compared to traditional, imperative programming models. Always ensure that the choice for a reactive system aligns with the use case, benefits, and team’s capability to work with it.

Does This Mean That The Web Container Can Be Tuned With Smaller CPU and Memory specs?

When transitioning from a traditional blocking model (like Servlet-based Spring MVC) to a non-blocking reactive model (like Spring WebFlux), there are potential benefits in terms of resource utilization. Let’s dive into how CPU and memory might be impacted:

  1. CPU Utilization:

    • Traditional Model: In a blocking system, if a thread is waiting for I/O (like a database call), it’s essentially idling, which is not necessarily a significant CPU overhead but rather a waste of the thread.
    • Reactive Model: With non-blocking systems, threads are not waiting idly. Instead, they’re freed up to handle other tasks. This could potentially lead to more efficient CPU usage since the CPU could be continuously processing tasks rather than waiting. However, context switching and handling more tasks might also increase CPU load.
    • Conclusion: Reactive doesn’t always mean reduced CPU usage. Instead, it often means more efficient CPU utilization. Depending on the workload and the nature of tasks, CPU specs might remain similar.
  2. Memory Utilization:

    • Traditional Model: Each thread consumes memory (for its stack, which can be around 1MB for a typical Java thread). If you have a high thread count to handle concurrent users, this can add up and lead to a significant memory footprint.
    • Reactive Model: With non-blocking systems, you can handle more tasks with fewer threads, leading to potential memory savings from reduced thread counts.
    • Conclusion: Reactive systems can often be tuned with a smaller memory footprint due to the need for fewer threads. However, always benchmark, as the reactive library and other factors can also consume memory.
  3. Tuning the Web Container:

    • Reactive Runtimes: When using a runtime like Netty (common with Spring WebFlux), the model is different from traditional servlet containers. Netty is designed for high concurrency with a smaller number of threads.
    • Traditional Containers: If you’re using WebFlux on a traditional servlet container (though less common), tuning might be closer to what you’d do for Spring MVC, but with some adjustments for the reactive nature.
  4. Other Factors:

    • Application Code: The efficiency of your application code, reactive or not, will influence resource requirements.
    • Reactive Overhead: The overhead of reactive programming libraries and the asynchronous operations themselves can impact resource utilization.

In conclusion, while the shift to a reactive model like Spring WebFlux can provide opportunities for more efficient resource utilization and potentially reduced memory specs (due to fewer threads), it doesn’t automatically guarantee lower CPU or memory requirements. The nature of your application, the efficiency of your code, the specific workloads, and other factors play a role. Always benchmark and monitor in realistic environments to make informed decisions about resource specifications.

If A New Application Is Created, Should The Team As A Whole Consider Spring WebFlux First Or Is It Overkill?

Whether to consider Spring WebFlux for a new application is a decision that should be based on the application’s requirements, the team’s familiarity with reactive programming, and the projected growth and scalability needs. Here are some factors to consider:

Application Requirements

Team Familiarity

Infrastructure and Dependencies


Projected Growth

Migration & Integration

In summary, while Spring WebFlux is powerful and offers many advantages for the right scenarios, it’s not a one-size-fits-all solution. Analyze the specific needs of your application and the strengths and weaknesses of your team. Starting with traditional Spring MVC and later migrating to WebFlux (if needed) is also an option, though migration can come with its own challenges. Always make informed decisions based on research, prototyping, and a clear understanding of your application’s requirements.

Is There A Difference In Overhead When Testing APIs Using Spring WebFlux vs Spring WebMVC?

Testing APIs in both Spring WebFlux and Spring WebMVC can be straightforward due to the comprehensive testing support provided by the Spring framework. However, there are differences in how you might approach testing, as well as some overhead variations:

Approach & Framework

Asynchronous Testing


Testing Blocking Calls

Integration Tests

Both Spring WebMVC and Spring WebFlux allow the use of the @SpringBootTest annotation, which loads the entire application context, providing a simulated environment that closely mirrors reality. However, for WebFlux, it’s imperative to ascertain that any integrated downstream services or databases are also non-blocking or are effectively mocked for your tests.

While the fundamental concepts of testing remain consistent between Spring WebMVC and Spring WebFlux, the reactive nature of WebFlux introduces nuances that testers must be aware of. If your team is new to reactive programming, anticipate some additional overhead in understanding and effectively testing WebFlux applications. However, once you’re familiar with the paradigms, testing WebFlux APIs can be as efficient and thorough as testing traditional Spring WebMVC APIs.

Will Spring WebFlux make efficient use of AWS Elastic Container Service?

Spring WebFlux can be efficiently used with AWS Elastic Container Service (ECS), just as any other application framework can. However, the unique characteristics of reactive applications, like those built with Spring WebFlux, can influence how they operate within container orchestration systems like ECS. Here’s a breakdown of how WebFlux might interact with ECS:

Efficient Resource Utilization

Reactive applications, particularly because of their non-blocking nature, have the capability to handle a substantial number of concurrent connections using a minimal number of threads. This efficiency translates into more economical memory consumption, especially beneficial in containerized contexts where memory quotas are typically stringent. With WebFlux’s optimal resource utilization, each container instance might be capable of managing more simultaneous requests than a conventional blocking application, which could reduce the requisite number of container instances.


ECS facilitates automatic scaling based on an array of metrics. Given the efficiency of WebFlux applications in managing sudden surges of requests, you may experience more seamless scaling sequences. Such smooth transitions can be especially beneficial during unexpected traffic surges.

Health Checks

ECS’s operation hinges significantly on health checks to ascertain the status of a container instance. It’s paramount to ensure that your WebFlux application integrates appropriate health check endpoints, like Spring Actuator’s /actuator/health endpoint, and that these are meticulously configured within ECS.


Reactive applications often uphold persistent connections, as seen in scenarios involving WebSockets or Server-Sent Events. It’s crucial to validate that any load balancers or network configurations incorporated with ECS are harmonious with these long-standing connections.

Configuration and Tuning

While WebFlux boasts its capability to manage an augmented number of requests with constrained resources, it’s imperative to fine-tune both the JVM and the application to align with a containerized environment’s expectations. One such critical aspect is guaranteeing that the JVM is acutely aware of container boundaries and abides by the memory and CPU constraints outlined by ECS.

Logging and Monitoring

Effective monitoring is pivotal, especially when navigating the realms of reactive applications, to preemptively identify potential challenges like thread pool saturation or backpressure occurrences. Tools, notably Amazon CloudWatch, can be synergized to observe and log essential metrics from your WebFlux application operating on ECS.

Database and I/O Operations

For WebFlux applications that interface with databases or other services primarily driven by I/O operations, it’s essential to affirm their compatibility with the non-blocking, high-concurrency modus operandi of your application. While this isn’t a consideration exclusive to ECS, it’s a cardinal point for all reactive applications.

Spring WebFlux can be effectively used with AWS ECS, and its reactive characteristics can offer advantages in containerized environments. However, it’s essential to understand the reactive paradigm thoroughly, ensure other parts of your system are compatible, and monitor the application’s behavior to make the most of it. Properly tuned and monitored, a WebFlux application on ECS can deliver high performance and efficient resource utilization.

In Conclusion

Throughout this session, we delved deep into the nuances of Spring WebFlux, contrasting it with the traditional Spring WebMVC approach and exploring its compatibility with various environments, especially AWS ECS. WebFlux’s reactive paradigm promises efficient resource utilization, adaptability, and high-concurrency management, making it an intriguing choice for modern web applications. However, as with any technology, its efficacy largely depends on the context of its application, comprehensive understanding, and proper integration with other system components.

For teams and developers evaluating a transition to or adoption of WebFlux, it’s crucial to weigh its benefits against the challenges posed by the reactive programming model. The decision should be informed by the specific requirements of the application, infrastructure considerations, and the team’s familiarity with reactive concepts.

AWS ECS’s potential synergy with WebFlux offers a glimpse into the future of containerized web applications that prioritize performance and resource efficiency. Yet, meticulous configuration, tuning, and monitoring remain paramount to harness its full potential.

Lastly, as we navigate the evolving landscape of web development, continuous learning and adaptation are essential. Whether it’s Spring WebMVC, WebFlux, or another emerging technology, the key is to choose tools and frameworks that align best with the project’s goals, the team’s expertise, and the anticipated challenges of the digital ecosystem.

Related Articles:

Spring • Custom Annotations & AnnotationUtils Post Date: 06 Dec 2023
Spring, a powerhouse in the Java ecosystem, is renowned for simplifying the development process of stand-alone, production-grade Spring-based applications. At its core, Spring leverages annotations, a form of metadata that provides data about a program but isn’t part of the program itself. These annotations are pivotal in reducing boilerplate code, making your codebase cleaner and more maintainable.
Spring • Custom Annotations & AspectJ In Action Post Date: 06 Dec 2023
In this article, we delve into the dynamic world of Spring Framework, focusing on the power of custom annotations combined with AspectJ. We’ll explore how these technologies work together to enhance the capabilities of Spring applications. For those already versed in Spring and the art of crafting custom annotations in Java, this piece offers a deeper understanding of integrating AspectJ for more robust and efficient software design.
Mastering Testing with @MockBean in Spring Boot Post Date: 01 Dec 2023
In the realm of Java application development, the @MockBean annotation in Spring Boot is pivotal for effective testing. Part of the org.springframework.boot.test.mock.mockito package, it facilitates the creation and injection of Mockito mock instances into the application context. Whether applied at the class level or on fields within configuration or test classes, @MockBean simplifies the process of replacing or adding beans in the Spring context.
Spring Boot MockMVC Best Practices Post Date: 16 Nov 2023
Spring MockMVC stands as a pivotal component in the Spring framework, offering developers a robust testing framework for web applications. In this article, we delve into the nuanced aspects of MockMVC testing, addressing key questions such as whether MockMVC is a unit or integration test tool, its best practices in Spring Boot, and how it compares and contrasts with Mockito.
Spring Boot • Logging with Logback Post Date: 19 Oct 2023
When it comes to developing robust applications using the Spring framework, one of the key aspects that developers need to focus on is logging. Logging in Spring Boot is a crucial component that allows you to keep track of the behavior and state of your application.
Spring • DevOps Best Practices with Spring Profiles Post Date: 19 Oct 2023
The integration of Spring with DevOps practices is integral to modern application development. This guide will provide a deep dive into managing Spring profiles efficiently within machine images like Docker, including essential security-specific configurations for production Spring profiles and the handling of AWS resources and secret keys.
Spring Boot • Environment Specific Profiles Post Date: 19 Oct 2023
When building a Spring Boot application, it’s essential to have different configurations for various environments like development (dev), testing (test), integration, and production (prod). This flexibility ensures that the application runs optimally in each environment.
Spring Validation • Configuring Global Datetime Format Post Date: 17 Oct 2023
In the world of Java development, ensuring proper data validation and formatting is crucial. One key aspect of this is configuring a global date and time format. In this article, we will delve into how to achieve this using the Spring Framework, specifically focusing on Java Bean Validation.
Spring Reactive • Best Practice for Combining Calls with WebClient Post Date: 17 Oct 2023
Modern applications require a high level of responsiveness and resilience, and the reactive programming paradigm fits the bill. In the Spring ecosystem, WebClient is a non-blocking, reactive web client used to make asynchronous calls.
Spring Java Bean Validation Post Date: 17 Oct 2023
The Spring Framework, renowned for its versatility and efficiency, plays a pivotal role in offering comprehensive support for the Java Bean Validation API. Let’s embark on an exploration into the world of Bean Validation with Spring.
Spring 5 • Getting Started With Validation Post Date: 17 Oct 2023
Validation is an essential aspect of any Spring Boot application. Employing rigorous validation logic ensures that your application remains secure and efficient. This article discusses various ways to integrate Bean Validation into your Spring Boot application within the Java ecosystem. We’ll also explore how to avoid common pitfalls and improve your validation processes.
Spring 6 • What's New & Migration Guide Post Date: 16 Oct 2023
The Spring Framework’s legacy in the Java ecosystem is undeniable. Recognized for its powerful architecture, versatility, and constant growth, Spring remains at the forefront of Java development. The release of Spring Framework 6.x heralds a new era, with enhanced features and revisions that cater to the modern developer’s needs.
Spring UriComponentsBuilder Best Practices Post Date: 16 Oct 2023
The Spring Framework offers an array of robust tools for web developers, and one such utility is the UriComponentsBuilder. This tool provides an elegant and fluent API for building and manipulating URIs. This article offers a deep dive into various methods and applications of UriComponentsBuilder, backed by practical examples.
Spring Field Formatting Post Date: 02 Oct 2023
Spring Field Formatting is a pivotal component of the Spring Framework, allowing seamless data conversion and rendering across various contexts, particularly in client environments. This guide provides an in-depth look into the mechanics, interfaces, and practical implementations of Spring Field Formatting, elucidating its significance in modern web and desktop applications.
Spring Validator • Resolving Error Codes Post Date: 01 Oct 2023
Data validation is paramount for web applications, ensuring user input aligns with application expectations. Within the Spring ecosystem, validation and error message translation are critical components, enhancing user experience.
Spring Validator Interface Post Date: 01 Oct 2023
Spring offers a robust framework for application developers, with one of its standout features being data validation. Validation is essential for ensuring the accuracy, reliability, and security of user input. In this guide, we’ll delve deep into Spring’s Validator interface, understand its significance in the context of web applications, and explore how to implement it effectively.
Spring Type Conversion Post Date: 01 Oct 2023
Spring provides a robust type conversion system through its core.convert package, offering a versatile mechanism for converting data types within your applications. This system leverages an SPI (Service Provider Interface) for implementing type conversion logic and a user-friendly API for executing these conversions during runtime.
Spring Framework Expression Language Post Date: 01 Oct 2023
Spring, the ever-evolving and popular framework for Java development, offers a myriad of functionalities. Among these, the Spring Expression Language (SpEL) stands out as a notable feature for its capability to manipulate and query object graphs dynamically. In this comprehensive guide, we unravel the intricacies of SpEL, shedding light on its operators, syntax, and application.
Spring Framework Annotations Post Date: 01 Oct 2023
Spring Framework has solidified its place in the realm of Java-based enterprise applications. Its annotations simplify the coding process, enabling developers to focus on the business logic. This article delves into the core annotations in the Spring Framework, shedding light on their purposes and usage. Through this comprehensive guide, we aim to provide clarity and depth on these annotations.
Spring Controller vs RestController Post Date: 01 Oct 2023
The Spring MVC framework stands out as one of the most robust and versatile frameworks in the realm of Java web development. At the heart of its dynamism are two key annotations: @Controller and @RestController. These annotations not only define the structure but also dictate the behavior of web applications. This exploration aims to provide a deeper understanding of these annotations, their respective functionalities, and when to optimally use them.
Spring Boot Conditional Annotations Post Date: 01 Oct 2023
The world of Java programming, notably within the Spring Framework, constantly evolves, offering developers powerful tools and techniques to streamline application building. One such tool that stands out is the @Conditional annotation. This robust tool in Spring Boot is an absolute game-changer, offering a range of built-in annotations that allow developers to control configurations based on multiple criteria.
Spring Bean Manipulation and the BeanWrapper Post Date: 01 Oct 2023
In the realm of Java-based applications, the Spring Framework is renowned for providing powerful tools to manipulate and manage bean objects. Central to this process is the BeanWrapper. This article delves into the essence of Bean Manipulation, shedding light on the BeanWrapper, and the various tools provided by the Spring Framework and java.beans package.
Managing AWS CloudFront Using Spring Shell Post Date: 26 May 2023
This article explores an efficient approach to deploying static pages in CloudFront while leveraging the content delivery capabilities of AWS S3 and the convenience of Spring Shell Command-Line Interface (CLI) using the AWS SDK for Java.
Spring Framework Events Post Date: 17 May 2023
Spring Framework provides a powerful event handling mechanism that allows components within an application context to communicate and respond to events. This mechanism is based on the Observer design pattern and is implemented using the ApplicationEvent class and the ApplicationListener interface.
Spring Bean Scopes Post Date: 16 May 2023
Understanding and Utilizing Bean Scopes in the Spring Framework In this article, we will delve into the concept of bean scopes in Spring Framework. Understanding and effectively utilizing bean scopes is essential for controlling the lifecycle and behavior of your beans, allowing you to enhance the flexibility and power of your Spring applications.
Spring 6 Error Handling Best Practices Post Date: 15 May 2023
Error handling and exception design are integral components of developing Spring RESTful APIs, ensuring the application’s reliability, stability, and user experience. These practices enable developers to effectively address unexpected scenarios, such as invalid requests, database errors, or service failures, by providing graceful error responses.
Spring Boot, Jackson, and Lombok Best Practices Post Date: 12 Apr 2023
This article discusses the recommended practices for using Jackson and Lombok in conjunction with Spring Boot, a popular framework for building enterprise-level Java applications.
Encrypting Properties File Values with Jasypt Post Date: 28 Mar 2023
Property files are text resources in your standard web application that contains key-value information. There may come a time when information should not be stored in plain sight. This article will demonstrate how to encrypt properties file values using Jasypt encryption module. Jasypt is freely available and comes with Spring Framework integration.
Spring Boot • Serialize Immutable Objects Post Date: 03 Nov 2021
This article illustrates how to serialize and write tests for immutable objects using Jackson and Lombok in Spring Boot.
Spring Boot Profiles & AWS Lambda: Deployment Guide Post Date: 20 Oct 2019
In this article, we will explore how to leverage the Spring Boot Profiles feature in an AWS Lambda Compute environment to configure and activate specific settings for each environment, such as development, testing, integration, and production.
AWS Lambda with Spring Boot: A Comprehensive Guide Post Date: 28 Apr 2019
This article explores the benefits of using Spring Boot with AWS Lambda, a powerful serverless compute service that enables developers to run code without worrying about server management. By integrating with the AWS cloud, AWS Lambda can respond to a variety of AWS events, such as S3, Messaging Gateways, API Gateway, and other generic AWS Resource events, providing an efficient and scalable solution for your application needs.
Secure SMTP with Spring JavaMailSender Post Date: 15 May 2016
This article discusses the use of Java Mail in the context of migrating email services to Google Apps For Your Domain. The author shares their experience with using the free service and encountered a problem with using the secure SMTP protocol to send emails programmatically through their old email account with the Spring JavaMailSender.