Design a messaging app like WhatsApp: 1-1 chats, groups of up to 150, media and presence
Role: Software Engineer
Category: System Design
Difficulty: medium
Interview Round: Other
Design a messaging app in the style of WhatsApp, WeChat or Messenger. The system manages the delivery and retrieval of chat conversations in real time.
It must support these features:
1. 1-1 chats, where users send and receive direct messages.
2. Group chats with up to 150 members.
3. Media sharing, where users exchange images, videos, voice notes and documents.
4. Push notifications that alert users to new messages in real time.
5. An online/offline indicator that shows each user's presence status.
Stating the non-functional requirements is part of the task. Examples of the kind of targets to set: availability over consistency, page loads under 300 ms, and 99.9% uptime.
```hint Finding the recipient
Each online client holds a long-lived connection to one particular server. Work out how the server that receives a message learns where the recipient is connected.
```
```hint Catching up after a reconnect
A phone that was offline for an hour needs to know which messages it missed. Think about what property of a message ID would make that check cheap.
```
```hint Use the group cap
The 150-member limit bounds the work one group message can create. Decide what that bound lets you do at send time.
```
### Constraints & Assumptions
- Group chats have at most 150 members.
- Unless the interviewer gives other numbers, assume 100 million daily active users who each send about 50 messages a day, and keep messages for 10 years.
- End-to-end encryption is out of scope.
### Clarifying Questions to Ask
- Can a user be signed in on several devices at once, and must every device show the full history?
- Do senders see delivery and read receipts (sent, delivered, seen) in 1-1 chats, in groups, or both?
- What size limits apply to videos and documents, and how long must old media stay downloadable?
- Should presence show only online and offline, or also a last-seen time?
- Must the service keep working when a whole region or datacenter goes down?
### What a Strong Answer Covers
- Non-functional requirements with concrete targets, and estimates of message rate and storage that separate text from media.
- A data model for users, devices, conversations, memberships and messages, with a database choice justified by the write rate and the main read pattern.
- The path of one message from sender to every recipient: the connection type, how the recipient's server is found, how IDs are generated and ordered, and what happens when a recipient is offline.
- How media is uploaded, stored, served and moved to cheaper storage as it ages.
- How presence is detected and broadcast, and how the system recovers when a chat server fails.
### Follow-up Questions
- A client sends a message, loses its connection before the acknowledgment arrives, and sends again. How do you make sure the message is stored and shown once?
- What would you change if groups could have 100,000 members?
- How would you add end-to-end encryption, and which server-side features would stop working?
- A chat server holding hundreds of thousands of connections crashes. What happens to those users and to the messages that were on their way to them?
Overview: Design a real-time messaging app with 1-1 chats, group chats of up to 150 members, media sharing, push notifications and an online indicator. It tests capacity estimates, data modeling, long-lived connection handling, message fan-out and ordering, offline delivery and presence tracking for 100 million daily users.