InterviewSolution
| 1. |
What is Reactive Programming? How it can be enabled using Spring? |
|
Answer» Traditional monolithic applications developed in the last few decades had the luxury of CONSIDERABLE response time, multiple hours of offline maintenance and smaller volumes of data. However, this is not acceptable with the modern applications serving high volumes round the clock with an expectation of sub-second response time with 100% availability. Reactive programming is ONE of the solutions for the above constraints, which is rapidly gaining popularity in cloud-based applications. It is a programming pattern that RECOMMENDS an asynchronous, non-blocking, event-driven approach for data processing. In the reactive style of programming, after making a request for the resource, the application continues to perform other tasks instead of WAITING for the response. When the data is available, the application should get the notification along with data in the form of call back function which handles the response as per business needs. Systems built as Reactive Systems are highly flexible, loosely coupled, and scalable. This makes them easier to develop and responsive to change. They are significantly more resilient and are able to handle failures gracefully. They are quite responsive and ideal for interactive applications. Spring Web Reactive brings reactive capabilities for web applications, which is based on the same fundamental programming model as Spring MVC. The base API is 'Reactive HTTP' as opposed to 'Servlet API' and runs only on Servlet Containers like Netty or Undertow. We need to add 'spring-boot-starter-webflux' to ENABLE Spring Reactive and 'spring-boot-starter-reactor-netty' as the default embedded reactive server; in the application dependencies. Creating a Spring Reactive Controller is similar to a typical Spring MVC Controller using @RestController and the required @RequestMapping annotations. |
|