17. Reactive Programming
Reactive Programming manages asynchronous data flows between producers of data and consumers
that need to react to that data in a non-blocking manner.
So, Reactive Programming is all about non-blocking applications that are asynchronous and
event-driven and require a small number of threads to scale. (Dzone.com)
37. References
1. SpringOne Platform 2016 Keynote - Reactive Spring
2. From Imperative To Reactive Web Apps
3. Reactive Programming With Spring 5
4. Doing Reactive Programming with Spring 5
Editor's Notes
Hi Everyone,
Welcome to our techtalk, and this is the first techtalk ever we have in our team, so basically our goal of this techtalk is to create the culture of Sharing, keeping with current and relevant technology so that we know what going on in the technology market.
For those who are new to our team, we are actually working on a project call CDV, we have a very diverse team 1 Philipino, 1 Cambodia, a couple of Americans, 1 Chinese, 2 Russians, and also Indian.
If we look at the execution model of how we are handling the requests in Spring MVC world. We know that the application run on the Servlet Container, and we have a number of incoming request from the clients, so what it does is that Servlet container will spawn every new Thread to handle the request so that it guarantee that each request is processed independently from the other.
Then it comes to the question that what if we have concurrent thousands of requests comping to the server, will the Servlet container running out of memory because of spawning new thread to handle each of the request? The answer is maybe, but luckily Servlet Container also has the concept of Threadpool that the a number of requests will be executed simontanously while the rest will be put in queue. However, if we continue to have many requests at the peak load eventually we will reach OutOfMemory exception.
So then what we do is that we try to scale the application horizontally by having a couple of JVM or instances and we have Load Balancer who try to balance the requests to different JVM.
So it is a simple model that we can use to build the application that scale pretty well and has taken us this far, and there is no reason to change if thing has already be been working just fine. However, over the last 10 years things have changed dramatically in the way we develop application.
In addition there is a concern that the more resources we used in scalling up the application will end up more costs we need to spend in our architecture design. So What would be the alternative? That’s why we come to our topic today which is “Non-Blocking Runtime”
The concept is pretty influent by thing that have already been proof by the Event Loop execution model done by NodeJS in which we have 1 Thread that run asynchronously to handle all the request in non-blocking way. But, in the context of the Reactive NonBlocking Runtime , the idea is to reduce the number of Threads compare to a lot of Threads used in Servlet Container. Which basically we have a couple of Threads who are responsible for handling all the requests. Each of the worker Thread have to be non-blocking, and that it comes to our next topic how to develop the non-blocking application.
In fact building non-blocking application is not really simple as we heard about developing application like that in NodeJS, we have the word like “Call back Hell”, and many other things, but with Project Reactor done by Pivotal in Spring 5 helps to leverage all the difficult works.