Design a Real-Time Chat Service for One-to-One and Group Messaging
MetaSoftware Engineer · OnsiteLast updated
A system design question on a real-time chat service with one-to-one and group conversations, instant delivery to online users, offline catch-up, and history across devices. It tests connection routing, per-conversation ordering, idempotent sends, message storage, group fan-out, and read receipts.
Design a real-time messaging service for a social network's chat product. Users exchange text messages in one-to-one conversations and in group conversations. Recipients who are online receive messages immediately, recipients who are offline receive them when they reconnect, and a user's conversation history is available on every device they use.
Clarifying Questions
- How many daily active users are there, how many messages are sent per day, and what is the largest group size?
- Which features are in scope: delivery and read receipts, typing indicators, presence, media attachments, end-to-end encryption?
- Must every one of a user's devices receive every message and share the full history?
- How long is message history retained?
- Should offline users receive push notifications?
Hints
Hint 1
Find the recipient's connection: Think about how the server locates the live connection of a recipient who may be attached to any one of many gateway machines, possibly from several devices.
Hint 2
Decide who sets the order: Decide what "in order" must mean for a conversation and which single component is allowed to assign that order.
Follow-up questions
- How do you guarantee that no message is lost or duplicated when a client's connection drops in the middle of a send?
- How would end-to-end encryption change the server design, especially for multiple devices and groups?
- A group grows very large. What changes in fan-out, receipts, and notifications?
- How would you implement "seen by" for group messages efficiently?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.