What is reactive programming?

A look at the tools helping to build those apps reliant on asynchronous data streams

keyboard

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.

Advertisement - Article continues below

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

Advertisement
Advertisement - Article continues below
Advertisement - Article continues below

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 Extensions

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.

Advertisement - Article continues below

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.

Featured Resources

Top 5 challenges of migrating applications to the cloud

Explore how VMware Cloud on AWS helps to address common cloud migration challenges

Download now

3 reasons why now is the time to rethink your network

Changing requirements call for new solutions

Download now

All-flash buyer’s guide

Tips for evaluating Solid-State Arrays

Download now

Enabling enterprise machine and deep learning with intelligent storage

The power of AI can only be realised through efficient and performant delivery of data

Download now
Advertisement

Most Popular

Visit/infrastructure/server-storage/355118/hpe-warns-of-critical-bug-that-destroys-ssds-after-40000-hours
Server & storage

HPE warns of 'critical' bug that destroys SSDs after 40,000 hours

26 Mar 2020
Visit/software/video-conferencing/355138/zoom-beaming-ios-user-data-to-facebook-for-targeted-ads
video conferencing

Zoom beams iOS user data to Facebook for targeted ads

27 Mar 2020
Visit/software/355113/companies-offering-free-software-to-fight-covid-19
Software

These are the companies offering free software during the coronavirus crisis

25 Mar 2020
Visit/mobile/mobile-phones/355088/apple-lifts-iphone-purchase-restrictions
Mobile Phones

Apple lifts iPhone purchase restrictions

23 Mar 2020