educative.io

Educative

The hash table for {userID, ConnectionObj}

hi @Design_Gurus,

regarding this paragraph:
" How can the server keep track of all the opened connections to efficiently redirect messages to the users? The server can maintain a hash table, where “key” would be the UserID and “value” would be the connection object. So whenever the server receives a message for a user, it looks up that user in the hash table to find the connection object and sends the message on the open request."

I understand the purpose of the hash table here, the part is that not clear to me is

  1. each chat server has a local version (only users connected to this server) of this hash table? if yes, how does it ‘discover’ users that are connected to other servers?
  2. if this hash table is a global table (all users), each chat server has the same copy of this table? how big it can get for 500M DAU?

Thanks,
Milo

From the chapter:

How do we know which server holds the connection to which user? We can introduce a software load balancer in front of our chat servers; that can map each UserID to a server to redirect the request.

An alternate would be to use an approach similar to Consistent Hashing to map UserIDs to servers.

thanks @Design_Gurus, i was thinking the same, so essentially in a distributed chat system to locate the recipient’s chat server, one has to query a centralized service OR use consistent hashing, correct?