Design a Chat System
Design WhatsApp or Slack. The hard problems are message ordering, presence detection, offline delivery, and keeping millions of persistent WebSocket connections alive.
What you will learn
- Explain why WebSockets are necessary for chat and when to fall back to long polling
- Design a message ordering scheme that is correct under concurrent sends
- Handle offline users with a durable inbox and push notification fallback
- Implement presence detection without hammering the database
Chat systems are a favourite interview topic because they require designing for state that lives on the wire, not just in the database. A chat connection is a long-lived session. Messages must arrive in order. Users go offline and need their backlog delivered when they return. And you need to know — at low latency — whether someone is online before deciding whether to ring their phone.
This walkthrough covers a WhatsApp-style 1-1 and group chat system.
Functional requirements:
- 1-1 messaging and group chats (up to 500 members)
- Messages are delivered in order and reliably
- Users see the other party's online/offline status (presence)
- Push notification when the recipient is offline
- Read receipts (delivered, read)
- File/image attachments
Non-functional requirements:
- Message delivery latency < 100ms (online recipient)
- Offline delivery: messages must survive indefinitely until the recipient comes online
- High availability — chat downtime during an outage is unacceptable
- Ordering: messages in a conversation must appear in the same order on all clients
Create a free account to read the full chapter — advanced chapters, progress tracking, and quizzes are free with sign-up.