node.js - Long-polling (user notification) with a RESTful architecture -


I am working on a simple restine API (on nodes) I think that the comfort means horizontal scaling is very much Unfortunately, I need some methods so that customers can be notified about certain incidents. For this reason, I was thinking of voting for a long time. I have a question about how it works with multiple servers. For example, here is an easy-to-use case:

  Both servers A and B are behind a normal load balancer User Alice posts a message on Bob's wall (request on server A) If Bob is online, he should be notified immediately (Long time voting on server B)  

How can the server send information to a bob, or does Server B know that Bob should be notified?

First of all, I do not know that to handle your notification channel on both clients and servers Why not use something like socket.io ? If available, will use web sockets (more efficient than longer voting) and then fallback in long pedestrian if there is no web socket.

There are several ways to handle the issue of informing a user connected to the server that generates the notification:

Connected Database

When a user connects Then it loads the load on a random server, but it is stored at the end until it connects to the server. A central database (such as perhaps a redis store) can make any server aware of which server bridegroom Currently connected to a user, it gives you the ability to see which server is currently connected to any user. Each server that handles user connections, just adds each user to the database with reference to their server ID when the user disconnects them and then removes them from the database Note: Since this information is constantly stored on disk There is no need to do and the size of the data is small, you can select a database that most or all information in memory It is better to keep re.

Hashed Connection

Some of the user's famous features such as their user id, a hash value are calculated and created a repeater algorithm to map hash values ​​to the server pool has gone. This is a hopeful task, in this way, when a server wants to inform Bob, they can call the same function which will find out which server Bob is connected to hash algorithm optimizer, such as today your If there are three servers, then palm users are broadcast evenly in three servers and if you have four servers yesterday, then the hashed user will be similar to the four servers. Are scattered throughout the West.

Multi-Connection

Since low-action websites are very scalable these days, so all users can connect to all servers and thus in each server there is a user The socket connection will be. It's easy infrastructure, but ultimately not as scalable.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -