How to Design a WhatsApp-Style Chat App (System Design Walkthrough)
Design a WhatsApp-style chat app step by step: WebSockets, delivery receipts, offline users, message ordering, group chats, media and scaling.
“Design WhatsApp” is one of the most common system design interview questions, and for good reason. It looks simple (send a message, show it on the other phone) but it touches almost everything: long-lived connections, delivery guarantees, ordering, offline users, group fan-out, media and huge numbers of concurrent users.
This walkthrough follows the same six steps as our system design interview framework: requirements, estimates, API, data model, high-level design, then deep dives. If a term is new, the glossary explains it in plain English.
Step 1: Requirements
Functional:
- One-to-one chat and group chat.
- Delivery status: sent (one tick), delivered (two ticks), read (blue ticks).
- Messages sent to an offline user arrive when they come back online.
- Online status / last seen.
- Images, voice notes and video.
Non-functional:
- Low latency. Messages should feel instant when both users are online.
- No lost messages. Once the sender sees one tick, the message must not disappear.
- Correct order within a conversation. Replies must not appear before the question.
- Works on bad mobile networks. Phones drop connections constantly, especially on the move.
Out of scope for now: voice and video calls, status/stories, payments. Say this out loud so the interviewer can redirect you.
Step 2: Estimates
These are interview assumptions, not WhatsApp’s real numbers:
- 10 million daily active users, each sending 40 messages a day → 400 million messages a day ≈ 4,600 messages per second on average, with peaks a few times higher in the evening.
- About 200 bytes per text message including metadata → roughly 80 GB of new message data per day, before replication.
- If 20% of daily users are connected at the same time, that is 2 million open connections to hold.
The last number drives the design. Two million persistent connections is a connection-management problem first, a database problem second.
Step 3: How clients talk to the server
Normal request/response HTTP is the wrong fit: the server needs to push new messages to the phone the moment they arrive. Polling every few seconds wastes battery and data and still feels slow.
The standard answer is a WebSocket: one long-lived, two-way connection between the app and a server. Messages, receipts and typing indicators all flow over it. When the app is closed or in the background, the operating system usually kills the connection, so offline delivery relies on push notifications (APNs on iOS, FCM on Android) to wake the app, which then reconnects and syncs.
A minimal set of client events:
send_message { clientMsgId, conversationId, body | mediaRef }
ack { clientMsgId, serverMsgId, seq } // server -> sender: "sent"
new_message { serverMsgId, conversationId, seq, senderId, body }
delivered { serverMsgId } // recipient -> server
read { conversationId, upToSeq } // recipient -> server
sync { conversationId, afterSeq } // after reconnect
Step 4: Data model
Chat is write-heavy and almost always read “latest messages in this conversation”. That access pattern suits a wide-column store such as Cassandra or ScyllaDB:
messages
partition key: conversation_id
clustering key: seq (ascending)
columns: message_id, sender_id, body or media_ref, created_at
conversation_members
conversation_id, user_id, last_delivered_seq, last_read_seq
Partitioning by conversation keeps each chat’s messages together, so “load the last 50 messages” is one fast read. A relational database can work at smaller scale; the point to make is that the query pattern, not fashion, picks the store.
A real-world note worth mentioning: WhatsApp encrypts messages end to end and, according to its published security documentation, keeps them on its servers only until they are delivered. That is a product and privacy choice. Many other chat apps store full history on the server so it syncs across devices. Ask the interviewer which one they want.
Step 5: High-level design
The main components:
- Gateway (connection) servers hold the WebSockets. They are stateful: each knows which users are connected to it.
- A session registry (for example Redis) maps
user_id → gateway server, refreshed by heartbeats with a short expiry. This also powers online/last seen. - Chat service validates messages, assigns sequence numbers, writes to storage and routes them.
- Message store as above.
- Push notification service for offline users.
- Media service with object storage (S3 or similar) and a CDN.
A load balancer spreads new connections across gateways. Since gateways only hold connections and do no heavy work, you add more of them as concurrent users grow (horizontal scaling).
The life of a message
- Ali’s app sends
send_messagewith a client-generated message ID over its WebSocket. - The chat service assigns the next sequence number for that conversation, writes the message to the store, and sends
ackback to Ali. One tick. Only acknowledge after the write is durable. - The chat service looks up Sara in the session registry. If she is connected, it forwards the message to her gateway, which pushes it down her WebSocket.
- Sara’s app replies
delivered. Two ticks for Ali. - When Sara opens the chat, her app sends
readup to that sequence number. Blue ticks. - If Sara is offline, the message waits in storage, a push notification goes out, and when her app reconnects it calls
syncwith the last sequence number it has.
Step 6: Deep dives and trade-offs
Delivery guarantees and duplicates
Mobile networks drop packets and connections all the time, so clients retry. Retries mean the server may receive the same message twice. The fix is idempotency: the server stores the client message ID and, if it sees the same one again, returns the original ack instead of saving a second copy. The result is at-least-once delivery with deduplication, which looks exactly-once to the user.
Ordering
Never order messages by the phone’s clock; phone clocks are wrong surprisingly often. Order by the per-conversation sequence number the server assigns. To assign it safely, make sure only one place hands out numbers for a conversation, for example by routing all of a conversation’s messages through the same partition of a message queue or using an atomic counter. Ordering across different conversations doesn’t matter, which is what makes this scale.
Group chats
For a group message you have two options:
- Fan-out on write: deliver a copy (or a pointer) to every member’s connection or inbox when the message is sent. Fast reads, more work per message. Fine for groups with a bounded member limit.
- Fan-out on read: store the message once and let each member pull it. Less write work, slower reads. Better for very large channels.
Chat apps with capped group sizes usually fan out on write. Read receipts in groups are tracked per member, which is why “read by everyone” is stored separately from the message.
Media
Don’t push a video through the chat servers. The sender uploads the file straight to object storage using a short-lived pre-signed URL, then sends a normal message containing only the media reference. Recipients download it through the CDN. Chat servers stay small and fast.
Presence without a storm
If every online/offline change were pushed to every contact, presence traffic could exceed message traffic. Instead, send presence only to users who currently have that chat open, and fetch “last seen” lazily when a chat is opened.
When a gateway dies
All its connections drop. Clients reconnect (with randomised backoff so they don’t all hit at once), land on another gateway, update the session registry and sync from their last sequence number. Because messages were stored before being acked, nothing is lost. That is the payoff of step 2 in the message flow.
Storage growth
Messages are append-only and partitioned by conversation, so the store shards naturally. Replicate each shard across machines for durability (replication), and accept that a read straight after a failover may be briefly stale (eventual consistency).
How to present this in 45 minutes
Spend the first ten minutes on requirements and numbers, sketch the components and the life of a message by minute 25, and save the rest for two or three deep dives the interviewer picks. You won’t cover everything above, and you shouldn’t try. What gets scored is clear trade-offs: WebSockets vs polling, fan-out on write vs read, server-assigned sequence numbers vs client clocks.
Practise it with feedback
Reading a walkthrough is the easy part; defending your design while someone pokes holes in it is the skill. That is what System Design for the AI Era trains: six live Saturday classes (7–9 PM PKT) for engineers with two or more years of experience, with reviewed design docs and a live mock interview at the end. Join the free demo class on Saturday 28 November at 7 PM PKT first and see if it fits.