# Design a Chat App (WhatsApp)

> Design one-to-one and group messaging with persistent connections, message storage, delivery receipts, presence and offline delivery. Free notes, key concepts,...

Canonical: https://www.internhack.in/roadmaps/tracks/system-design/case-chat-app
Last updated: 2026-11-28

Design one-to-one and group messaging with persistent connections, message storage, delivery receipts, presence and offline delivery.

Advanced · about 5 hours · difficulty 4/5

Learn first: [HTTP, Connections and Real-Time Protocols](https://www.internhack.in/roadmaps/tracks/system-design/http-for-system-design), [NoSQL Data Models and When to Use Them](https://www.internhack.in/roadmaps/tracks/system-design/nosql-data-models), [Design a Notification System](https://www.internhack.in/roadmaps/tracks/system-design/case-notification-system)

WhatsApp serves billions of messages a day with famously small teams. Designing it tests real-time connections, storage at scale and delivery guarantees.

### Requirements

- One-to-one and group chats (groups up to a few hundred or thousand members), text and media.
- Sent, delivered and read receipts; online and last seen presence.
- Offline users receive messages when they reconnect; message order preserved per chat.
- Low latency, very high availability, end-to-end encryption.

### Connections

Clients keep a persistent **WebSocket** (or MQTT-style) connection to a **chat server**. A **session service** (Redis) maps user_id to the chat server holding their connection. Millions of connections are spread across many servers; servers are stateful, so use consistent routing and handle reconnects gracefully.

### Message flow (one-to-one)

1. Sender's chat server receives the message, assigns a **message ID** (time-ordered per conversation) and persists it.
2. It acks the sender (single tick).
3. It looks up the recipient's chat server and forwards the message; if the recipient is offline, it stays in their **pending inbox** and a **push notification** is sent.
4. The recipient's client acks delivery (double tick) and later read (blue ticks); these acks flow back as small events.

### Storage

Messages are write-heavy and read by conversation and time, a natural fit for a **wide-column store** partitioned by conversation_id and clustered by message ID (Cassandra, ScyllaDB, HBase). Media goes to object storage via pre-signed URLs and a CDN; the message carries only a reference.

### Groups and presence

Small groups: fan out a copy (or a pointer) to each member's inbox on write. Large groups and channels: store once and let members pull. Presence uses heartbeats with a TTL in Redis; broadcast changes only to contacts who are online, and batch them.

### Pitfalls

- Using HTTP polling for chat at this scale.
- Global ordering across all chats; you only need order per conversation.
- Forgetting idempotent message IDs, so client retries create duplicates.

You are ready to move on when you can trace a message from sender to an offline recipient and back to blue ticks, naming every component and store it touches.

## Key concepts

- **WebSocket connection servers**
- **Session registry (user to server)**
- **Message IDs and per-chat ordering**
- **Delivery and read receipts**
- **Offline inbox and push**
- **Wide-column message storage**
- **Group fan-out**
- **Presence with heartbeats**
- **End-to-end encryption basics**

## Mini project

Build a chat prototype: two WebSocket servers, Redis for the session registry and pub/sub between servers, Postgres or Cassandra for messages, and sent/delivered/read receipts. Show a message reaching a user connected to the other server and an offline user receiving it on reconnect.

## Check yourself

User A is connected to chat server 3 and user B to chat server 7. How does A's message reach B, and what happens if B's server crashes mid-delivery?

## Free resources

- [How Discord stores trillions of messages](https://discord.com/blog/how-discord-stores-trillions-of-messages) (Discord)
- [The WebSocket API](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) (MDN)
- [High Scalability](https://highscalability.com/) (High Scalability)

Previous: [Design Search Autocomplete (Typeahead)](https://www.internhack.in/roadmaps/tracks/system-design/case-search-autocomplete) · Next: [Design a News Feed (Instagram, Twitter, LinkedIn)](https://www.internhack.in/roadmaps/tracks/system-design/case-news-feed)

## More in HLD Case Studies: Large Products

- [Design a Chat App (WhatsApp)](https://www.internhack.in/roadmaps/tracks/system-design/case-chat-app)
- [Design a News Feed (Instagram, Twitter, LinkedIn)](https://www.internhack.in/roadmaps/tracks/system-design/case-news-feed)
- [Design a Video Streaming Platform (YouTube, Hotstar)](https://www.internhack.in/roadmaps/tracks/system-design/case-video-streaming)
- [Design Ride Matching (Uber, Ola, Rapido)](https://www.internhack.in/roadmaps/tracks/system-design/case-ride-matching)
- [Design a Payment System (UPI-style)](https://www.internhack.in/roadmaps/tracks/system-design/case-payments-upi)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [System Design Roadmap](https://www.internhack.in/roadmaps/tracks/system-design)
