Would like to know if this is the right direction for scalable chat messenger?
I would prefer a slightly different approach. Your ideas are correct, but I would like to add a little more to the same. I happened to create such a chat messenger a few years ago, and it should have looked like a watsapp. I am sure that when you googled, you would come across the XMPP Extensible Messaging and Presence Protocol. we used openfire as a server supporting connections. Concept that you explained where
Say Friend 1 and Friend 2 are online . Friend 1 has established HTTP web connection to web server 1 and Friend 2 has established HTTP web connection to web server 2. Friend 1 send the message to Friend 2.
called federation, and openfire can run in federated mode. After reading your comments, I came across one queue at a user point. I am sure that you already know that this approach is not scalable because it is very resource intensive. A good approach would be to use an Actor structure such as an aka. Each actor is similar to a stream of light weight in java, and each actor has a mailbox. therefore, in this case it will take care of the messaging.
So, your script turns into Friend 1, opens a connection to the openfire xmpp server and initializes the actor Friend 1. When he types a message, he is transferred to the actor Friend 1 in-box (each actor in akka has Inbox in his memory). This is reported to the xmpp server. The server has its own database, and since it integrates with other xmpp servers, it will try to find if friend 2 is online. The xmpp server will store the message in its db until it goes online. When friend 2 establishes a connection with any of the xmpp servers, the creator of friend 2 is created, and his presence extends to all other servers, and server xmpp 1 will notify friend 2. Friend-2-incoming user will receive a message
Additionally: there is also the possibility of receiving a receipt. As soon as Friend2 reads the message, the delivery receipt can be sent to friend 1 to indicate the status of the message that has been read, unread, delivered, not delivered, etc.
source share