Card image cap

Kumar Pallav
Kumar Pallav
I am a passionate java programmer, Open Source and Microservices lover, blogger and online instructor. I create Simple Short Tutorials

Building blocks of Reactive Systems

• Kumar Pallav

Reactive Systems consists of 2 major components.

  1. Observable
  2. Observer


Think of an example of watching movie , The movie is being played and it keeps emitting events in form of stream of screens and voice. Here in this example , we can say that Movie is an Observable type.

Similarly if you log in to twitter it has streams of incoming tweets. In Facebook it is stream of posts.

If we take a more traditional approach of programming for streaming events , we will be choking our systems. The traditional mode of approach will also result in losing states of data or else it will be too overwhelming for it to keep all the state and work on it.

Let’s think an example of a shopping cart. If you add an item or update its quantity , each of your action is an event. In traditional approach you don’t track all the events but the final value of cart. If we keep the states of all of the events in real time using traditional approach with database at backend , we will be making lot of database related operations which will lead to memory and performance issues.

###reactive_building_blocks.png Observer

Observer is one who observe observable. If you are watching movie you are the observer. In order to observer we have same basic rules, which in reactive methodology are translated as methods.

To watch movie , we need ticket i.e. subscription (onSubscribe) , as the move starts we observer streams of events (onNext ) , once movie compleats (onCompleate) we know the movies is finished we stop observing it or if there is an error (onError) viz. power failure, we still stop observing.

Similarly while designing reactive streams and systems we keep in mind of reactive manifesto . By adhering those principals above methods help us to keep things simple yet effective.

In next section we will see how to create Observable and observer.