What is Reactive Programming?
Reactive Programming is a way to build a scalable architecture that is resilient and quick to react to stimuli.
Think of a spreadsheet. You have 3 cells A1, B1 and C1. You can configure an equation against C1 as the SUM(A1, B1). Here Cell C1 can respond to the changes of A1 and B1 without any further actions from the user.
Here we can say this spreadsheet is reactive towards the changes.
The Cell C1 has been subscribed to the changes in cells A1 and B1, and does a simple addition over the updated values and displays the same.
Isn’t this Cool? How can we use a similar strategy to programming? That’s reactive programming: changes propagate throughout a system automatically.
In RP, Observables emit data and send it to the subscribers. In the above example, Cells A1 & B1 are Observables, and Cell C1 is a subscriber.
Reactive representation of Spreadsheet Cells
Why Reactive Programming?
Reactive programming is about creating an architecture that supports:-
Here are some of the examples where Reactive programming is used
When to use Reactive Programming?
Applications nowadays have an abundancy of real-time events of every kind that enable a highly interactive experience to the user. We need tools for properly dealing with that, and Reactive Programming is an answer.
Evolution of Reactive Programming in Different languages
Rx* library family is widely available for many languages and platforms
Let's look at Code Now
Notice the Observable
Here we are subscribing to the stocks feed on StockServer and prints the values and errors.
Download demo code from https://github.com/sujithps/stock-exchange