I found articles which have an overview of the architecture of facebook messenger, But I would like to understand in depth.
Here are the few things I know (Correct me if I am wrong)
- When a sender sends a message we need to store in some persistent data store If the receiver is online at that time we need to send those messages to the receiver. This should happen seamlessly, i.e, Receiver should not poll for new messages
Here are the few thoughts I had in mind
Idea 1 - Inside application server, we will maintain one channel per receiver push all new messages related to that receiver into the channel, read from this channel and push it to the client.
How can we maintain till what message receiver read per sender/receiver thread(i.e, conversation)?
Idea 2 - Inside application server, we will maintain one channel per sender-receiver combination (i.e, conversations) and read from all the receiver channels and push it to the client.
How can we handle these many channels per receiver?
Here are the few questions I have
Application Server Stack
- How to forward messages directly if the receiver is online?
- How to maintain multiple clients of the same receiver i.e, if the receiver is logged in via mobile app, web browser. How to forward messages to all clients?
- How to maintain connections in the application server, so that application server will push messages if any, instead of client continuously polling the server?
- How can we maintain mark as read feature for each conversation?
- How to push all unread messages of the receiver when the receiver comes online?
- How to fetch conversation history in an efficient manner?
- How to scale up to millions of senders/receivers?
Persistent Data Store
- What is the best suitable data store for chat kind of applications?
- What is the storage format of data?
Please comment the reason if at all you want to downvote