What is Nats Streaming Server?

Abhishek Singh
3 min readDec 25, 2020

--

EXAMPLE: Instagram clone using Microservice architecture with features like CRUD operation on post their likes and comments.

Here Post service Needs to update the Like Service and Comment Service if a new post is created or an existing post is deleted.

The same goes for Comment Service its needs to update the Like Service if a new comment is created or an existing comment is deleted.

Here we’re creating a Web of Network Calls.

IT’S A MESS !!!

Here we need someone to simplify our Web of Network Calls.

In the Early days when we want a connection of Tatasky, Dish Tv, D2h on our TV.

We have to Select which channel we want to subscribe to from the list of channels.

If you don’t subscribe to your favorite Sports channel, then you’re gonna miss your sports match cause you can’t access your sports channel.

So that law applies here too.

NATS Streaming Server is a lightweight data streaming system built on NATS.

Basically, it's like an event bus.

clients are not directly connected to the publisher, but instead communicate with the publisher through NATS Server.

When a post is created Post Service Publish an Event called ‘POST CREATED’

(along with the created post data) into the Post Channel

Now whichever service is Subscribed to this Post Channel receives the Event called ‘POST CREATED’ and also the created the post data.

Here Like Service gets the ‘POST CREATED’ Event along with the created post data.

Now Like Service will save the post data and set the number of likes to zero.

The same goes to comment service it will save the post data and set the number of comments to zero.

When a new comment is created Comment Service Publish an Event called ‘COMMENT CREATED’ (along with the created comment data) to the Comment Channel.

Now the only Service which is subscribed to this channel is Like service

So Only the Like service will get the Event ‘COMMENT CREATED’ and also the created comment data which will be saved and set the number of likes to zero.

In the first scenario where a new Post is created, there Post Service is the Publisher and Like and Comment Service is the Subscriber.

In the second scenario where a new comment is created there, Comment Service is the Publisher and the Like Service is the Subscriber.

--

--

Abhishek Singh
Abhishek Singh

Written by Abhishek Singh

0 Followers

I'm a Full Stack Web Developer but mostly focused on Backend Development.

No responses yet