×
IBORN Logo
A woman sitting at a table with a laptop, focused on her work.

Introduction to Reactive Programming

Sara Pavlovikj
November 14, 2019

 

Reactive Programming is a new declarative paradigm. It makes it possible to work with finite or infinite data flows asynchronously, allowing it to propagate generating changes in the application. As it is indicated by the title, it ‘reacts’ to the data by executing a series of events.

Reactive programming is related to the Observer design pattern: when there is a change of state in an object, the other objects are notified and updated accordingly. Therefore, instead of probing events for changes, events are performed asynchronously so that observers can process them.

The idea behind using asynchronous programming is simple: to reduce the inefficient use of resources. The way that is achieved is simple – using resources that would otherwise be inactive, for they would be waiting for the activity of a particular component. With reactive programming new data notifications are sent to customers without them having to make a request, as data entry and exit are asynchronous. Therefore, the normal design of the input and output processing is reversed. This approach frees the client to do other things while waiting for new notifications.

Its conception and evolution have been linked to the publication of the Reactive Manifesto, which established the basis of reactive systems, including four core principles:

  • Responsive: they ensure the quality of the service by complying with established response times.
  • Resilient: they remain responsive even when faced with error situations.
  • Elastic: they remain responsive even when the workload is increased.
  • Message-driven: they minimize the coupling between components by establishing interactions based on the exchange of messages asynchronously.
A man sitting at a desk, focused on a computer screen, working diligently.


You may wonder about the key motive to develop this paradigm. It stems from the need to respond to scaling limitations that are present in prevalent development models. These scaling limitations cause wasted use of the CPU due to I/O, memory overuse (large thread pools) and inefficiency of blocking interactions. 

How to apply reactive programming?

Now comes the part that interests us most. How do we apply reactive programming, where do we incorporate it in our technologies?

For those who use Java, the two libraries recommended by the community are:

RxJava: this library and its version 1.x were the pioneers in Java reactive development, (currently they are going for version 3). They are fully integrated into frameworks such as Spring MVC, Spring Cloud, and Netflix OSS. 

Project Reactor: It was conceived with the involvement of the team responsible for RxJava 2, so they share much of the architectural base. Its main advantage is that being part of Pivotal, it has been chosen as the foundation of the future Spring 5 WebFlux Framework. This API introduces the Flux and Mono types as Publisher implementations, which generate a series of 0… N and 0… 1 element respectively.

For those who use Javascript frameworks, these are our recommendations:

React + redux-saga: it is a reactive framework in itself, and it is managed by integrating a global state to the application which is updated through side effects.

NgRx: is a framework for building reactive applications in Angular. It provides state management to create explicit maintainable applications, storing a single state and the use of actions to express state changes, in addition to side effects isolation, entity collection management, and router links. 

Benefits of reactive programming

These are some of the main benefits of applying this type of programming:

Scalability: By using reactive programming we obtain a weakly coupled implementation that is scalable and tends to isolate errors. Scalability refers to the ability to scale horizontally and quickly. For those who don’t know, a system scales horizontally when its performance improves with the addition of nodes. For example, adding a new computer to a system that balances the load between the old and the new can improve the performance of the entire system. This also applies to programming, either with services on the backend side or modules and/or components on the frontend side.

Two individuals working on laptops while seated on a couch.

 

Savings: The efficient use of resources, allows us to spend less on servers and data centers. One of the main premises of reactive programming is that more can be done with less. Specifically, you can process higher workloads with fewer threads.

With the rise of web applications that deal with large amounts of data, these became increasingly complex. In many cases, they demand visualization of data from many different sources. The data has to be updated on a recurring basis or in real-time. This is why reactive programming has become increasingly popular in recent years. It facilitates and optimizes the management of these types of data flows.

If you have any questions about reactive programming and/or think you may find it useful in some of your projects, don’t hesitate to contact us.

More similar blog posts:

A woman sitting at a table with a laptop, focused on her work.
What’s new in Angular 9

After several months of delays and considerable uncertainty, version 9 of Angular, one of the most widely used Front-End development frameworks in the world, was finally released.

A woman sitting at a table with a laptop, focused on her work.
How feature flags benefit various roles in teams

Everything you need to know about feature flags. Explore how this simple yet transformative tool enhances agility, quality, and collaboration across diverse roles in a team. 

A woman sitting at a table with a laptop, focused on her work.
Achieving future-proof software

As IT engineers we take great pride when what we do improves an aspect of society. Even the little things, like improving loading time by half a second mean a lot.

A woman sitting at a table with a laptop, focused on her work.
Enhance your business with an intelligent ERP

It is common among company owners and managers to think that the digital transformation process is completed simply by implementing an ERP system. But, this is a misconception, as that’s just the beginning. The question “And, now what?” follows logically.

A woman sitting at a table with a laptop, focused on her work.
SaaS: Advantages of Cloud Computing for SMEs

ew technologies can be very beneficial for small and medium-sized enterprises (SMEs), especially technologies that can improve and simplify business management processes without increasing costs.

A woman sitting at a table with a laptop, focused on her work.
Business benefits of software consulting and development services

We live in a globalized world where companies that aim to be successful on an international scale are facing a lot of competition. In order to be a fast-growing company and climb high up the ladder, you should have a large team. 

A woman sitting at a table with a laptop, focused on her work.
Top 8 myths about custom software development

Myths, false beliefs and assumptions obstruct the communication and software development process. Is it really custom software development slow, expensive and complicated? It doesn't necessarily have to be that way.

A woman sitting at a table with a laptop, focused on her work.
Custom software development or off-the-shelf software?

The dilemma that most innovative software companies and business owners face at some point.

A woman sitting at a table with a laptop, focused on her work.
Software development company vs. Freelancer

If you’re reading this, you probably have a great idea for a web project or an app. I’m pretty sure you have some ideas about how to do it.

A woman sitting at a table with a laptop, focused on her work.
Deliver the right software with SBE

If you work with software development I’m sure that you’ve already heard words like BDD, TDD, ATDD, etc. But, have you heard about SBE? SBE or Specification by Example is a collaborative method for specifying requirements and test.

A woman sitting at a table with a laptop, focused on her work.
Callbacks - A thing of the past

If you are a web developer you probably spend a considerable amount of time handling requests, waiting for things from external sources and then handling the requested data. The problem is quite common and not easily manageable on the client-side.

A woman sitting at a table with a laptop, focused on her work.
The awesome power of JavaScript functions

Functions in JavaScript are first-class citizens. Yeah, functions are what JavaScript is all about. But let’s dive in, let’s get into a bit more details.

A woman sitting at a table with a laptop, focused on her work.
That one time every page run on a single thread

If you’ve ever seen website you would’ve noticed pages loading fast and all sorts of shenanigans, how is it even possible to run all that via a single, lone thread. Well, it’s not really a lone thread, in the sense that JavaScript isn’t doing all the work on its own. It’s simple then it sounds real.