Design a chat application (like WhatsApp).
Answer
- Features: 1:1 and group messages, online status, delivered/read receipts, history, offline delivery.
- Clients keep WebSocket connections to chat servers; a session service maps user → server.
- Send flow: message → server → persist (partitioned by conversation, ordered by time/ID) → route to the recipient's server via pub/sub → push; if offline, push notification and deliver on reconnect.
- Message IDs per conversation for ordering and deduplication (client retries).
- Groups: fan-out on write for small groups.
- Presence with heartbeats and TTLs; media in object storage + CDN; mention end-to-end encryption.
Practice this question in Repaso