The whole course ▾

System Design · Mock interview 4 of 20

Design WhatsApp

Updated 22 Oct 2026 · By Akshay, software engineer, India · 9 min read

Design a chat app like WhatsApp.

Try it first

Before you read the interview, answer the question yourself. Give yourself 10 minutes: say your design out loud, or sketch it on paper. What would you ask? Which numbers matter? Which boxes, and what's the hard part? Then read on, and score yourself with the feedback at the end.

The video for this mock interview is coming soon.

New System Design videos go up at 6 pm. Subscribe on YouTube so you don't miss it.

Got a doubt? Ask in the comments under the video.Subscribe

Requirements

Requirements
Clarifying questions
->
Groups too? -> Yes, up to 500 people
->
Photos and calls? -> Text only today
->
Scale? -> 500M daily users
->
Keep messages forever? -> Only until delivered
Functional requirements
Send to a person or a group
Deliver later if the phone is off
Sent, delivered and read ticks
Online and last seen
Push notification when offline
Non-functional requirements
->
500M daily users, 20B messages a day
->
Delivered in under a second if online
->
Never lost; in order within a chat
->
Highly available
Out of scope
Photos, voice notes and calls
Searching old messages
Encryption details
interviewer
Hi, thanks for coming in. Shall we begin?
candidate
Sure. I'll draw as I go.
interviewer
I'd like you to design a chat app, like WhatsApp.
candidate
Okay. I've used it a lot, which is exactly why I want to slow down. Chat hides a few hard problems: phones that are offline, messages that must stay in order, and a huge number of open connections. Let me ask some questions first.
interviewer
Sure.
candidate
One-to-one only, or groups too?
interviewer
Groups too, up to five hundred people.
candidate
Photos, voice notes, calls?
interviewer
Text only today.
candidate
What scale?
interviewer
Five hundred million daily users.
candidate
And do we keep messages on the server forever?
interviewer
No. Like WhatsApp, the server holds a message only until every recipient's phone has it.
candidate
That changes the storage a lot. Good to know.
candidate
So, what it must do. Send a message to a person or a group. Deliver it later if their phone is off. Show the ticks: sent, delivered and read. Show who's online, and when they were last seen. And send a push notification when a message arrives for a phone that isn't connected.
candidate
And how well. Five hundred million daily users, sending maybe twenty billion messages a day. Delivered in under a second when the other phone is online. A message is never lost, and within one chat, everyone sees the same order. And it has to be highly available.
interviewer
Twenty billion sounds about right.
candidate
I'll leave out photos, voice notes and calls, searching old messages, and the details of end-to-end encryption. Does that match what you had in mind?
interviewer
Yes. Start with one-to-one, and then we'll get to groups.

Estimation

Estimation
Back of the envelope
20B messages ÷ 100,000 s = 200,000/s
Peak ~ 3 × = 600,000 messages/s
~100M phones connected at peak
100,000 sockets per server -> 1,000 servers
20B × 100 B = 2 TB a day, deleted on delivery
WHAT THE NUMBERS DECIDE
100Mopenconnections:
dedicatedconnection
servers.600,000writes/s:a
sharded,write-heavystore.
candidate
Let me get two numbers: messages a second, and open connections.
interviewer
How much traffic, and how many connections?
candidate
I'll use a hundred thousand seconds in a day, and a peak around three times the average.
candidate
Twenty billion messages over a hundred thousand seconds is two hundred thousand a second on average, and a peak around six hundred thousand. If one user in five is online at the busiest moment, that's about a hundred million phones connected at once. At a hundred thousand open sockets per server, that's about a thousand connection servers. Storage: a hundred bytes a message is two terabytes a day, but most of it is deleted within seconds, on delivery.
candidate
So, a hundred million open connections means dedicated connection servers, separate from everything else. Six hundred thousand messages a second, each saved before it's acknowledged, means a sharded store built for heavy writes. And since messages are deleted once delivered, storage stays small.
interviewer
Good. That question about keeping messages paid off.

API and data

API and data
Chats
chat_id, members
Messages
chat_id, seq, sender,
text
Delivery state
user, chat, delivered,
read
1 : many
1 : many
Over the socket
1
send(chat, client_id, text) -> ack
+ seq
2
message(chat, seq, text) -> to
the phone
3
delivered / read (chat, up to seq)
4
GET /chats/{id}?after=seq:
catch up
candidate
Next, the API. Chat doesn't make a request per message. It keeps one connection open.
interviewer
So what does the API look like?
candidate
A WebSocket per phone, with a few message types, plus one ordinary request for catching up.
candidate
The phone sends a message with the chat ID, the text, and a client ID it made up, so a resend after a dropped connection isn't stored twice. The server answers with an acknowledgement and the message's sequence number in that chat. The server pushes incoming messages down the socket. Phones send receipts: delivered, or read, up to a sequence number. And after being offline, a phone can catch up with one ordinary request.
interviewer
Why WebSockets, and not polling?
candidate
Polling a hundred million phones every few seconds would be mostly empty answers. An open socket lets the server push the moment a message arrives.
candidate
Three tables. Chats: the chat ID and its members. A one-to-one chat is just a chat with two. Messages: the chat ID, a sequence number within the chat, the sender, and the text. And delivery state: for each user in each chat, the highest number delivered to their phone, and the highest read. I'd shard messages by chat ID, so one chat's messages live together, in order.
interviewer
Why does delivery state matter?
candidate
It makes catching up cheap. A returning phone sends its last number per chat, and gets only what's newer.

High-level design

High-level design
Alice's
phone
Connection
server
holds Alice's
socket
Chat
service
Messages
DB
sharded by
chat
send
1
new
message
2
save, seq
812
3
ack: one tick
4
Session
map
user ->
server
Connection
server
holds Bob's
socket
Bob's
phone
where's
Bob?
5
deliver 812
6
message
7
delivered
8
The ticks
1
One tick: saved on the server
2
Two ticks: on Bob's phone
3
Blue ticks: Bob opened the chat
TWO QUESTIONS
Amessageissaved
beforeit's
acknowledged.Butwhat
ifBobisoffline?
interviewer
Okay. Let's see the design.
interviewer
Walk me through Alice sending Bob a message.
candidate
In two halves: getting it safely onto the server, then getting it to Bob.
candidate
Alice's phone sends the message over its WebSocket to its connection server, which passes it to the chat service. The chat service gives it the next sequence number in that chat, eight hundred and twelve, and saves it in the messages DB, which keeps copies on several machines. Only once it's saved does Alice get the acknowledgement, and her phone shows one tick. From that moment, the message can't be lost.
interviewer
That save adds latency.
candidate
A few milliseconds. That's the price of never losing a message, and it's worth it.
candidate
Now to Bob. The chat service asks the session map, a fast store like Redis that every connection server keeps up to date, which server holds Bob's socket right now. It forwards the message to that connection server, which pushes it down the socket to Bob's phone. Bob's phone answers: delivered. That receipt travels back the same way, and Alice sees two ticks.
candidate
So the ticks are just acknowledgements you can see. One tick: saved on the server. Two ticks: delivered to Bob's phone. Blue ticks: Bob opened the chat, and his phone sent a read receipt up to eight hundred and twelve. One receipt can cover many messages at once.
interviewer
Nice.
interviewer
So a message is saved before Alice sees one tick?
candidate
Yes. One tick means safely stored. The open question is what happens when Bob's phone is off, and the session map has no server for him.
interviewer
Let's look at that.

Deep dive: offline, and in order

Deep dive: offline, and in order
Phone timestamps
Phone clocks are often wrong
Two phones disagree
Gaps are invisible
A sequence per chat
One counter per chat, on the server
Everyone sees the same order
A gap shows what's missing
THE CHOICE
Asequencenumberper
chat,fromtheserver;
theclientIDmakes
resendssafe.
High-level design
Alice's
phone
Connection
server
holds Alice's
socket
Chat
service
Messages
DB
sharded by
chat
send
1
new
message
2
save, seq
812
3
ack: one tick
4
Session
map
user ->
server
Connection
server
holds Bob's
socket
Bob's
phone
where's
Bob?
5
deliver 812
6
message
7
delivered
8
Push
service
APNs /
FCM
Apple and
Google push
Bob is
offline
notify Bob
The ticks
1
One tick: saved on the server
2
Two ticks: on Bob's phone
3
Blue ticks: Bob opened the chat
TWO QUESTIONS
Amessageissaved
beforeit's
acknowledged.Butwhat
ifBobisoffline?
interviewer
Let's go into the everyday hard case.
interviewer
Bob's phone is off for three hours. What happens to his messages?
candidate
Store and forward. Keep each message until it can be delivered, the way email has worked for decades.
candidate
The message is already saved, so nothing is lost. The session map has no server for Bob, so the chat service hands a small job to a push service, which asks Apple's or Google's push system, APNs or FCM, to show a notification. When Bob's phone comes back, it reconnects and asks for everything after the last sequence number it has, in each chat. Once every member has a message, the server deletes it.
interviewer
Now, Alice sends two messages a moment apart, and they arrive the wrong way round. How do you keep order?
candidate
There are two options.
candidate
Option one: sort by the time on the sender's phone. But phone clocks are often wrong, two phones disagree, and you can't tell if a message is missing. Option two: the server gives every message a sequence number within its chat, from one counter per chat, and phones sort by it. Everyone sees the same order. And if a phone has eight hundred and ten and eight hundred and twelve, it knows eight-eleven is missing, and fetches it.
candidate
I'd go with the sequence per chat. Since messages are sharded by chat ID, each chat's counter lives on one shard, so one busy chat never slows another. And the client ID means a resend after a dropped connection is recognised, not stored twice.
interviewer
Does that work for groups?
candidate
The same way. One counter per group chat.
interviewer
Bob's phone drops in a lift and reconnects to a different connection server. Is anything lost?
candidate
No. The new server updates the session map, and Bob's phone asks for everything after its last sequence number. A message that was on its way to the old server was never acknowledged as delivered, so it's sent again, and Bob's phone ignores any number it already has. At-least-once delivery, made harmless.
interviewer
Good.

Deep dive: groups and presence

Deep dive: groups and presence
Group fan-out
1
Store the message once, in the chat
2
Look up 500 members' servers
3
One batch per connection server
4
Offline members: a push each
PRESENCE, CHEAPLY
Heartbeatsrefresha
TTLinRedis;presenceis
sentonlytopeople
lookingatthatchat.
interviewer
You said one-to-one first. Now, groups.
interviewer
A message goes to a group of five hundred people. How does it reach all of them?
candidate
Store it once, deliver it many times.
candidate
The message is stored once, in the group's chat, with one sequence number, not five hundred copies. The chat service looks up where all five hundred members are connected, in one request to the session map. It groups them by connection server, and sends one batch to each server, which fans out to its own sockets. Offline members get a push notification each, and catch up when they reconnect.
interviewer
And a broadcast channel with a hundred thousand followers?
candidate
Then pushing to everyone the moment anyone posts gets expensive. For huge audiences, I'd flip it: followers pull new posts when they open the channel, like a news feed. Push for small groups, pull for huge ones.
interviewer
How do online and last seen work for five hundred million users, without drowning the system?
candidate
Every phone connecting and disconnecting is a change someone might want to see, so I'd keep it cheap.
candidate
Each connection server sends a heartbeat for its users every half a minute or so, refreshing a key in Redis that expires on its own. No heartbeat, and the user drops to offline. Last seen is written when the socket closes. And presence isn't broadcast to every contact, only to people who have that chat open right now, which is a tiny fraction.
interviewer
And privacy settings?
candidate
Who can see your last seen is a product rule, checked before sending. It doesn't change the architecture.

Wrap-up

Wrap-up
Next steps
1
End-to-end encryption: keys on phones
2
Photos: object storage and a CDN
3
Regions near users
4
Watch delivery time and backlog
5
Rate limit spam senders
INTERVIEWER'S FEEDBACK
Strong:connectionserverswitha
sessionmap,storeandforward,a
sequenceperchat.Nexttime:sizethe
sessionmapoutloud.Verdict:hire.
interviewer
We're almost out of time.
interviewer
What would you improve with more time?
candidate
Here's what I'd tackle next.
candidate
First, end-to-end encryption: keys live only on the phones, so the server stores text it can't read. Second, photos, through presigned uploads to object storage and a CDN. Third, regions near users around the world. Fourth, I'd watch the time from send to delivered, and the backlog of undelivered messages. And fifth, rate limit spam senders.
interviewer
Which matters most to users?
candidate
Delivery time. If it creeps up, people notice before any alarm does.
interviewer
Okay, let's stop there. That was strong. You split the connection servers from the rest, the session map finds anyone's socket, store and forward handles offline phones, and the sequence per chat keeps the order. You explained the ticks as acknowledgements, which I liked. One gap: you never sized the session map. A hundred million entries is a few gigabytes, so it fits, but say it. I'd say a hire.
candidate
Thanks. I'll size the cache next time.
Interviewer's feedback

Strong: connection servers with a session map, store and forward, a sequence per chat. Next time: size the session map out loud. Verdict: hire.

Score yourself

Interviewers score these seven things. Give your own attempt a tick for each one you did.

  • Asks before drawing. Agrees what the system does, and how well: scale, speed, consistency.
  • Turns users into requests a second and bytes a day, and says what the numbers decide.
  • A small, clear contract, and a data model that fits how the data is read.
  • A working path end to end before any detail. Every box has a reason.
  • Picks the hard parts, compares two options, and chooses one with a trade-off said out loud.
  • What breaks, what happens then, and how users notice. Retries, duplicates, limits.
  • Thinks out loud, checks in with the interviewer, and takes a hint without losing the thread.

0 of 7

Your progress stays on this device.
New System Design videos at 6 pm

Lessons on weekdays, the week's revision on Saturday, a mock interview on Sunday.