Design a Chat App
System Design Cases: lesson 3 of 20
Finding the socket is harder than sending the message.
Lesson 3 of 20 · 7 min
Design a Chat App
Step 1 of 12
A million phones, each holding one open socket to one of many gateways.
The Idea
Deliver a message in under a second and let any device read it back later. Assume one million connected users and 50 000 messages a second at peak, so every phone holds an open socket to one of many gateways.
Real-World Example
A hotel switchboard. Rooms never dial each other directly: the board knows which line each guest is on, connects the two, and writes the message down when nobody picks up.
The Tradeoff
Persisting the message before acknowledging puts a write on the hot path, and it is the only reason delivery survives a crashed gateway. Acknowledging first is faster and loses messages. The registry mapping user to gateway is the piece that goes stale the moment a phone drops off a train.
Your turn
Put the steps in the right order.
- Ask the session registry which gateway holds the recipient
- Persist the message and give it a sequence number
- Push it down that socket, or queue a notification if there is none
- The sender's open socket carries the message to its gateway
Mini quiz
1 / 3