Design a Real-Time Chat Service for One-to-One and Group Messaging
Company: Meta
Role: Software Engineer
Category: System Design
Difficulty: medium
Interview Round: Onsite
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.
```hint 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 Decide who sets the order
Decide what "in order" must mean for a conversation and which single component is allowed to assign that order.
```
### 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?
### What a Strong Answer Covers
- Persistent client connections and a routing layer from user and device to gateway
- Per-conversation ordering and idempotent sends that survive retries
- A storage model for conversations and messages optimized for appends and recent-history reads
- Offline delivery and multi-device sync on reconnect
- Group fan-out and how very large groups change the design
- Receipts and presence without overwhelming the system
- Failure handling for dropped connections, gateway crashes, and duplicate sends
### 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?
Overview: 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.