Design the backend for a chat app. Users send messages to individuals or groups of up to 500 people. Messages must arrive within a second when the recipient is online, be stored so users can scroll back through history, and never be lost once the sender sees them as sent.
Functional requirements
Send and receive one-to-one messages
Group chats of up to 500 members
Scroll back through message history
Show who is online
Non-functional requirements
Messages reach online recipients in under 1 second at p99
No message is lost once acknowledged to the sender
Message order is preserved within a conversation
Constraints and scale
50 million daily active users
10 million concurrent connections at peak
40 messages per user per day on average
You will practise
Choose a real-time transport (WebSockets) and scale stateful connections
Fan out group messages efficiently
Model message storage for fast history reads
Show 2 hints
Persistent connections are stateful: how does a sender's server find the recipient's server?