Chat System (WhatsApp / Slack)
Real-time bidirectional messaging with offline delivery and group support.
You send a message and it appears on your friend's phone before you have put yours down. Two ticks, then two blue ticks.
Everything else on the web waits to be asked. Your browser requests a page, the server answers, the connection closes. Here the server has to reach a phone it is not currently being asked anything by, and do it in under a few hundred milliseconds, ten million times over.
Run the numbers on that last part. If a fifth of fifty million daily users are online at the evening peak, that is ten million connections held open at once, spread over a fleet, and something has to know which machine holds which person.
Connection state is what makes chat harder than any ordinary API, and almost every decision in this chapter comes back to it.
Lessons
4 in this chapter- Requirements and EstimationMessages per second is easy; millions of open connections is the real number.2 min
- Message Flow Across ServersTwo users on two different servers is the problem; a pub/sub backbone is the answer.2 min
- Storage and Offline DeliveryChat history is an append-only time series, and offline sync is just a cursor into it.3 min
- Groups, Receipts, and PresenceThe features users take for granted are where the write amplification hides.2 min