Scope
Functional
- 1:1 and group chats (up to 1,000 members); text and media.
- Sent / delivered / read receipts; online and last-seen presence.
- Offline users receive messages on reconnect; push notification when offline.
- Multi-device sync (phone + web).
Non-functional
- Delivery latency < 500 ms p99 when both users are online.
- No message loss once the sender sees one tick; per-conversation ordering.
- End-to-end encryption: servers cannot read content.
Out of scope: voice/video calls, payments, channels/communities.
Size
- 500M DAU, 40 messages/day each → 20B messages/day ≈ 230k/s average, ~700k/s peak.
- ~150M concurrent connections; at ~200k per gateway → ~750 gateway servers.
- Text storage: 20B × 200 B = 4 TB/day. Many products keep messages only until delivered; we'll keep a server copy for multi-device sync with retention.
APIs and data model
Over the WebSocket (binary frames, protobuf):
→ send {client_msg_id, conv_id, ciphertext, type}
← ack {client_msg_id, server_seq, ts} (one tick)
← msg {conv_id, server_seq, sender, ciphertext}
→ recv_ack {conv_id, up_to_seq} (two ticks)
→ read {conv_id, up_to_seq} (blue ticks)
→ sync {conv_id → last_seq, ...} (on reconnect)| Store | Key | Notes |
|---|---|---|
| Messages (Cassandra/ScyllaDB) | PK (conv_id, bucket), clustering server_seq DESC |
Append-only, per-conversation ordered |
| Inbox / sync state | user_id → {conv_id → last_delivered_seq} |
Drives offline sync |
| Conversations / members (SQL) | conv_id, member list |
Low volume, relational |
| Session registry (Redis) | user_id/device → gateway |
TTL + heartbeats |
The architecture
The 30-second summary
"Clients keep WebSocket connections to stateless-ish gateways; a registry maps users to gateways. The chat service, sharded by conversation, assigns per-conversation sequence numbers, persists to a wide-column store before acking, then routes to recipients' gateways or triggers push. Clients dedupe by client message ID and order by sequence, and sync by last-seen sequence on reconnect. Groups store once and fan out notifications per gateway."
Follow-up questions the interviewer may ask
- How do group chats with 1,000 members work?
- How do read receipts work without flooding the system?
- How do you support end-to-end encryption?
- How do you sync history to a new device?
Model answers to each of these are in the book.