Moving into the subscription model

Ranjith Raj D
2 min readApr 22, 2022

Subscribe to the stream of events and react to the event.

Many of you have subscriptions to multiple providers like newsletters, magazines or movie streaming services. Receiving daily newspaper and don’t even touch it. Busy folks have no time rest of us forget the subscription.

Have you ever planned to create a clone of yourself and watch all newly added movies on Netflix? Highly optimized solution for your money and your time.

Cloning is possible in Sci-fic movies. Employing a thread to watch the stream of events has scope in the programming world. In short, Subscribe to event streams and apply the reaction. The reactive paradigm has an easy way to achieve this.

Image courtesy: www.freecodecamp.org

Cloud-native frameworks recommend performing the asynchronous computation to make the most of the resources available.

Let’s glimpse a few terms popularly heard during asynchronous computation implementation.

Concurrency — One cooks the two dishes at the same time.

Parallelism — Two different cooks prepare two unique dishes at the same time.

Reactive programming

Reactive programming helps build software that responds to events. Events can be anything, like drag and drop in web applications or a dashboard of monitoring sensors.

We can take Rxjs here out of all other different reactive framework flavours. Search for the best fit on ReactiveX if you are looking for another programming language support.

const subscription = observable.subscribe({
next(x) { console.log(' It is data :' + x); },
error(err) { console.error('something wrong occurred: ' + err); },
complete() { console.log('done'); }
}); // creates subscription object

There are three different channels for the stream subscription. Rx has the name for the stream called observable.

  • Next is the data channel
  • Error is an exception channel. Error is also data. It is not the end of the stream. The stream can still flow.
  • Complete is call to say that stream is done.

Reactive System

A system that satisfies the below behaviours

  • Responsiveness
  • Elasticity
  • Resilience
  • Message-driven

--

--

Ranjith Raj D

Software Architect ✦ Full stack developer ✦ Artist ✦ Autodidact ✦ Codeaholic ✦ https://www.linkedin.com/in/ranjithrajd/