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.10 How does group chat work?
3 min read+10 XP
- Store once, deliver per member. A group message is one row; delivery fans out to each member's devices, like a small pub/sub topic (Chapter 23).
- Encryption: the sender encrypts the message once with a group key (WhatsApp's security whitepaper describes "sender keys" for this), and the server fans out the same ciphertext, instead of the sender encrypting it a thousand times.
- Cost grows with size. A 1,024-member group (WhatsApp's limit since 2022) sending 200 messages a day means about 205,000 deliveries and 409,000 delivery and read receipts a day.
- Receipts in big groups: aggregate them ("delivered to 1,010, read by 312") and send updates in batches.
- Membership changes need care: a new member shouldn't read old messages; a removed member must not get new ones. Re-key the group when members leave.
Memory code: "Encrypt once, store once, fan out to members, summarise the ticks."