Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 642
user1670498 Avatar asked Nov 02 '15 06:11

user1670498


1 Answers

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

like image 196
baynezy Avatar answered Oct 27 '22 18:10

baynezy