38. Design a Chat App (WhatsApp)
1
The interview prompt2
38.1 What do you ask first?3
38.2 How big is this, really?4
38.3 What are the doors?5
38.4 What do we store?6
38.5 What does the whole system look like?7
38.6 How does the WebSocket gateway work?8
38.7 How do message IDs and ordering work?9
38.8 How do delivery and read ticks work?10
38.9 How does offline delivery work?11
38.10 How does group chat work?12
38.11 How does media work?13
38.12 What would you say in the last five minutes?14
Score yourself15
Variations to practise16
Sources17
Code lab38. Design a Chat App (WhatsApp)
Score yourself
3 min read+10 XP
Score yourself
Give yourself 0, 1 or 2 points per row.
| Area | 0 points | 1 point | 2 points |
|---|---|---|---|
| Requirements | Started drawing | Send and receive | Order, duplicates, offline, multi-device, groups and encryption agreed |
| Estimates | None | Numbers, not used later | Connections and message rate drove gateways and sharding |
| API and data | Skipped | REST only | WebSocket messages with client_id, seq, delivered/read; cursors per device |
| High-level design | Server polls | Gateways without routing | Store-then-deliver, registry routing, push + sync walked |
| Deep dive | Hand-waved | One topic | Ordering and dedupe, ticks across devices, offline sync or groups done properly |
| Trade-offs | None named | Named when asked | Raised unprompted (per-chat order, retention, receipt cost, E2E limits) |
| Communication | Long silences | Mostly clear | Thought out loud, checked in, managed time |
12 to 14: strong hire signal. 8 to 11: solid, polish the weak rows. Under 8: redo the round in a week, timer on.
The bar: fresher vs SDE-2
| Fresher | SDE-2 | |
|---|---|---|
| Transport | WebSocket | Gateway tier, registry, heartbeats, reconnect storms |
| Ordering | Timestamps | Per-chat sequence from one writer; client IDs for dedupe |
| Ticks | Sent and read | Stored / all devices / read, "up to N" acks, privacy setting |
| Offline | "Store and forward" | Per-device cursors, push nudges, deletion after delivery |
| Groups and media | Loop over members | Sender keys, receipt aggregation, encrypted blobs with keys in messages |
Common mistakes
- Ordering by client timestamps.
- No client ID, so a retried send appears twice.
- Delivering before storing, so a crash loses messages.
- Two grey ticks after the first device acks, ignoring the user's other devices.
- Sending big media through the chat socket instead of object storage.
Quick check
Five questions on this chapter. Pick an answer, then check it.
quiz