Card 06/ 07
Practice: A First Design for a Chat Application
Requirements in, patterns out, each choice tied to the pressure behind it.
Producing a first design from a brief, the whole of this subject in one exercise, is practised here on a chat application. Work through requirements, estimates, parts and patterns in that order, and tie each choice to the pressure that justifies it, before opening the worked answer.
The brief. A chat app for 20 million daily active users, each sending 40 messages a day, about 1 KB each, kept for a year. Messages must appear for the other person within a second. Users are mostly in Europe and the Americas. Users on poor mobile networks often resend a message that seemed to fail. Each user can send photos.
- Name two functional and two non-functional requirements.
- Estimate peak messages a second and a year's storage.
- Name the parts and patterns, each with its pressure.
Check your design
- Functional: send a message to a person or group; see new messages as they arrive; send a photo. Non-functional: delivery within a second; no message lost or shown twice; available across two continents.
- Estimates: 800 million messages a day is about 9,300 a second on average, about 27,800 at a peak three times the average. A year at 1 KB each is about 292 TB.
- Parts and patterns:
- WebSockets to each client, because both sides send at once.
- Stateless chat servers, scaled out, behind a load balancer, with a shared record of which server holds each user's connection, because one server cannot hold millions of connections.
- A queue or log between servers and storage, because writes arrive in bursts and storage must not slow delivery.
- A database built for heavy writes, partitioned by conversation, because 292 TB a year outgrows one machine.
- An idempotency key on each message, because clients resend.
- Object storage and a CDN for photos, because they are large, read many times and requested from two continents.
- A spare of every part on the path, because chat down is the product down.
← → move through sections and cards