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.

Advertisement - Article continues below
Advertisement - Article continues below

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.

Advertisement - Article continues below

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.

Advertisement - Article continues below

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.

Advertisement - Article continues below

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

Digital Risk Report 2020

A global view into the impact of digital transformation on risk and security management

Download now

6 ways your business could suffer if you don’t backup Office 365

Office 365 makes it easy to lose valuable data regularly, unpredictably, unintentionally, and for good

Download now

Get the best out of your workforce

7 steps to unleashing their true potential with robotic process automation

Download now

8 digital best practices for IT professionals

Don't leave anything to chance when going digital

Download now

Most Popular


The top ten password-cracking techniques used by hackers

10 Feb 2020
operating systems

How to fix a stuck Windows 10 update

12 Feb 2020
Policy & legislation

What is the Computer Misuse Act?

17 Feb 2020

Microsoft to add Defender antivirus software to Linux, iOS and Android

21 Feb 2020