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)
38.2 How big is this, really?
3 min read+10 XP
Step 2: Estimates (5 minutes)
Assume about 100 bytes of encrypted text per message, a peak factor of 3, and 100,000 connections per gateway server (Chapter 21).
| What | Working | Result |
|---|---|---|
| Messages a day | 500 million × 40 | 20 billion |
| Messages a second | 20 billion ÷ 86,400 | ≈ 231,000 average, ~700,000 at peak |
| Text stored a day | 20 billion × 100 bytes | ≈ 2 TB a day (more with metadata) |
| Open connections | given | 200 million at peak |
| Gateway servers | 200 million ÷ 100,000 | ≈ 2,000 |
| A 1,024-member group, 200 messages a day | 1,023 × 200 deliveries; × 2 for receipts | ≈ 205,000 deliveries, ≈ 409,000 receipts |
What the numbers say, out loud:
- "Connections are the scaling problem: 200 million long-lived sockets need a dedicated gateway tier (Chapter 21)."
- "Hundreds of thousands of writes a second to the message store: shard it by chat."
- "Receipts can outnumber messages in groups; batch them."
Interviewer pushback:
- "Do you keep messages forever?" → That's a product choice. With end-to-end encryption, many apps keep messages on the server only until all devices have them (plus a safety window), and the history lives on devices and in user-controlled backups. That cuts storage enormously. I'll design for "store until delivered, then delete".
Memory code: "Count connections first, then messages, then receipts."