user1670498
user1670498

Reputation: 389

Node.js Server Sent Events with Load Balancer

I am working on a node.js based Web application that needs to be able to push data down to the browser. The Web app will be sitting behind a load balancer.

Assuming the Web app has a POST REST API as:

/update_client

and assuming there is a third-party application calls this API to push some data to the Web app, and then the Web app pushes the data down to the browser.

Now assuming I have two servers behind the load balancer, with the Web app running. A browser client connects to server 1 to listen on the event. Then the other applications hits the /update_client API at the server 2. Now since the two activities happen on two different servers, how can server 2 notify server 1 to send the data to the connected clients?

And what if I am using auto scaling, with dynamic number of servers behind the load balancer?

Upvotes: 9

Views: 5659

Answers (1)

baynezy
baynezy

Reputation: 7046

You need to have some kind of shared resource behind the servers so they all know about updates. I show how to use Redis Pub / Sub for this in a blog post I wrote recently.

Server Sent Events with Node JS

Upvotes: 7

Related Questions