Design a real-time messaging platform like WhatsApp or Facebook Messenger. Handle 1:1 and group messaging, online presence, read receipts, media sharing, end-to-end encryption, and guaranteed message delivery for 2 billion users.
What to design
What are the core functional requirements for the chat system?
What are the non-functional requirements? Consider scale, latency, message ordering, and reliability guarantees.
Design the core APIs — sending messages, managing groups, fetching chat history, and presence updates.
Which database would you use for message storage? How do you model conversations and handle chat history retrieval?
How would you manage millions of concurrent WebSocket connections? What happens when a chat server goes down?
How would you design the message flow for 1:1 chat — from sender to receiver, including offline delivery?
How would you handle group messaging? What changes compared to 1:1?
How would you implement read receipts and message delivery status (sent, delivered, read)?
How would you track and broadcast online/last-seen presence to contacts?
How would you handle media (image/video) sharing efficiently, especially on slow mobile networks?
How would you implement end-to-end encryption so the server cannot read messages?