Switching to Spring Webflux for API development - a pragmatic approach
Spring Webflux is a great framework when it comes to concurrency and efficiency. If you are considering Spring Webflux for API development, then this article will help you evaluate your choice.
Plan for the learning curve
Webflux is not just another spring module; it is going to present your team with a paradigm shift. There is a learning curve, rather a steep one. The developer's way of thinking should change. It is a known fact that reactive programming, in general, has a steep learning curve. Hence if you are on a time-critical project and the developers are new to reactive programming then it's a NO GO.
On the other hand, if you have plenty of time on hand and the team is excited about learning a new technology then it's a GO.
Understand the limitations
Some of the libraries in Webflux are still getting matured. For example, if you have to use an RDBMS, then the r2dbc library may present you with some challenges. I know projects that had faced performance issues and had to switch to JDBC. JDBC works with Webflux, then it is not reactive. There is no point in using a reactive framework if the database calls are going to be blocking calls. On the other hand, if you are using MongoDB then the webflux integration is pretty good.
Another example is caching. Unlike spring MVC, you can't just annotate your functions with @Cacheable and expect it to work. Many caching libraries are not reactive, and the Webflux way of configuring caching is not so easy.
The point here is, you should evaluate the fitment of webflux in your tech stack before finalizing it as the API framework.
Go one module at a time, don't go big bang
If the team is new to the reactive paradigm, then start with a small module first. Reading the web flux documentation alone is not going to help write quality code or debug it. Developers would need sufficient hands-on experience.
Evaluate the Cost-effectiveness
No doubt that Webflux is more efficient than normal spring MVC. But you can always scale your spring MVC application horizontally. Compare the cost of few additional servers vs development time, upskilling and maintenance. If your team is not well versed with reactive stack then the cost incurred could be much more than that of few extra servers on the cloud.
Like they say, "servers are cheaper than developers!"
If your team has strong reactive programming skills then this should not be a concern.
Summary
Webflux is an excellent framework in terms of efficiency and performance. But it is not a silver bullet to make all your APIs efficient. Before choosing it, evaluate how well it suits your team, tech stack, timelines & budget.
Delivery Project Lead at Mphasis | Microservices | Cloud | NoSQL | Docker | Kubernetes
3 年Debugging reactive streams one of the big challenge..
Associate Director at S&P Global Market Intelligence
3 年Great article santhosh, agree with your views of usage.
Lead Engineer @ Lowe's Companies, Inc. | Experienced Software Architect with a proven track record in designing and developing cloud-native distributed systems utilizing Java, Kotlin, Apache Kafka and Spring Boot.
3 年It is grate article Santhoshkumar Krishnakurup, thanks for sharing with us.