Design a chat application like WhatsApp
HardConceptSocial Platforms
Answer
Requirements: one-to-one and group messaging with low latency, delivery and read receipts, online presence, delivery to offline users, and message history that persists across devices.
- Connections: clients hold WebSocket connections to chat servers; a session registry such as Redis maps each user to the server holding their connection so messages can be routed.
- Storage: messages go to a wide-column store such as Cassandra, partitioned by conversation ID and sorted by a time-ordered message ID, which preserves ordering within each chat.
- Offline users: messages are stored and delivered on reconnect, with a push notification sent in the meantime.
- Trade-off: acknowledging only after the message is persisted adds a little latency but prevents loss; group fan-out is cheap for small groups but needs care for very large ones.
More in Social Platforms
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | Design a photo-sharing service like Instagram | Concept | Medium | Read the answer to Design a photo-sharing service like Instagram | |||
| 2 | Design a typeahead (search autocomplete) system | Concept | Medium | Read the answer to Design a typeahead (search autocomplete) system | |||
| 3 | Design a news feed system | Concept | Hard | Read the answer to Design a news feed system | |||
| 4 | Design a chat application like WhatsApp | Concept | Hard | Read the answer to Design a chat application like WhatsApp |