What is reactive programming?
A look at the tools helping to build those apps reliant on asynchronous data streams
Getting the right data to the right part of an application at the right time can be a challenge for many developers. If those streams of data don't come at the right time, all hell could break loose (or the app just stops working for a bit). Reactive programming is a method for overcoming such problems.
Reactive programming is a technique used to create applications that can cope with asynchronous data streams. Developing apps in this way can improve the user experience.
Such techniques can make an application seem more responsive. The application doesn't free when waiting for a data stream to come online.
Events, messages, calls, and even failures, can be turned into streams of data. An application using reactive programming will see these streams and react to them using its means to filter, create, transform, and connect any of those streams.
The code within a reactive application creates data streams of anything and from anything, such as HTTP requests, messages, notifications, changes to variables, cache events, sensor measures, and clicks. When this happens, the application becomes intrinsically asynchronous.
Reactive programming can turn virtually anything to a data stream to manage in an asynchronous manner. It also makes that job of handling errors simpler and makes code more flexible, readable, supportable, and simple to write.
The four principles of reactive programming
There are four principles to adhere to when creating reactive applications.
First, a responsive application is the main aim. It should be fast in reacting to all users.
Second, it should be resilient. This means it should apply suitable design and architecture principles in order to ensure responsiveness in all conditions.
Third, it should be scalable. I.e. it should be easy to upgrade on demand to guarantee responsiveness under numerous load conditions.
Lastly, the foundation of a scalable, resilient, and responsive system is its message-driven architecture. A message-driven application may be event-driven, actor-based, or both.
Reactive programming as a concept has been around for over 20 years but didn't take off until the introduction of Reactive Extensions. Reactive Extensions (also known as ReactiveX) are APIs or asynchronous programming with observable streams. This is how reactive programming works.
ReactiveX has two classes; observable and observer classes. An observable class is the data source of streams or events and an observer class is the one that uses (or reacts to) the produced elements.
An observable can have multiple observers so each data item produced will be received by each observer. In ReactiveX an observer subscribes to an observable. An observable then produces streams of data which an observer listens and reacts to. This sets off a series of operations on a data stream.
A subject is an observable extension that also implements an observer interface. This means that subjects can act as both observers and observables.
We can also apply operators to a stream. These define how and when the observables should produce streams. Most operators execute functions on an observable and return an observable.
Top 5 challenges of migrating applications to the cloud
Explore how VMware Cloud on AWS helps to address common cloud migration challengesDownload now
3 reasons why now is the time to rethink your network
Changing requirements call for new solutionsDownload now
All-flash buyer’s guide
Tips for evaluating Solid-State ArraysDownload now
Enabling enterprise machine and deep learning with intelligent storage
The power of AI can only be realised through efficient and performant delivery of dataDownload now