Watch the 2-minute explanation from a free SDE Skills session:
“Design WhatsApp” (or Messenger, or Slack) is one of the most common system design questions. The core is small: send a message, deliver it fast, keep it in order, and don’t lose it when someone is offline. What the interviewer is really testing is how you handle real-time connections and ordering at scale.
No messenger launched with a billion users. Begin with 1:1 chat, get it right, and make the design easy to extend to groups, media and read receipts later. (session clip at 8:28)
Functional
Non-functional
| What | Math | Result |
|---|---|---|
| Daily active users | given | 500 million |
| Messages per day | 500M x 30 | about 15 billion |
| Messages per second | 15B / 86,400 | about 175,000 (plan for peaks of 2-3x) |
| Storage per day | 15B x 100 bytes | about 1.5 TB |
(session clip at 4:30) Storage grows by about half a petabyte a year, so plan for partitioning from day one. See back-of-the-envelope estimation for the method.
Polling every few seconds wastes battery and adds delay. Keep a WebSocket open between each online device and a chat server. Push notifications (APNs, FCM) only wake the app; they are not a reliable delivery channel for the message itself. (session clip at 47:08)
Each chat server holds many open sockets, and operating-system limits (like file descriptors) cap how many. One mock interview tells a real outage story where that limit capped socket counts, so mention it. (session clip at 1:15:15) Keep a small session service (user to chat-server mapping) so any server can find where the receiver is connected.
Phone clocks drift, so client timestamps can’t give a reliable global order. Let the server assign a sequence number per conversation. You only need order inside a conversation, not across all of them, which keeps it cheap. Also be ready to defend your storage choice instead of reaching for “just use NoSQL”. (session clip at 1:27:44)
Here is the core logic, in memory, small enough to explain on a whiteboard:
from collections import defaultdict
class ChatServer:
"""Orders messages per conversation and holds them until each device acks."""
def __init__(self):
self.seq = defaultdict(int) # conversation_id -> last sequence number
self.log = defaultdict(list) # conversation_id -> [(seq, sender, text)]
self.members = {} # conversation_id -> set of user ids
self.acked = defaultdict(int) # (user, conversation_id) -> last seq delivered
self.online = {} # user -> callback for an open WebSocket
def send(self, conv, sender, text):
self.seq[conv] += 1 # server assigns the order, not the client clock
msg = (self.seq[conv], sender, text)
self.log[conv].append(msg)
for user in self.members[conv]:
if user != sender and user in self.online:
self.online[user](conv, msg)
return msg[0]
def ack(self, user, conv, seq):
self.acked[(user, conv)] = max(self.acked[(user, conv)], seq)
def sync(self, user, conv):
"""Called on reconnect: everything after the last acked sequence number."""
last = self.acked[(user, conv)]
return [m for m in self.log[conv] if m[0] > last]
if __name__ == "__main__":
s = ChatServer()
s.members["c1"] = {"alice", "bob"}
got = []
s.online["bob"] = lambda conv, m: got.append(m)
s.send("c1", "alice", "hi")
(Tested: offline messages come back in order after reconnect, nothing is delivered twice after an ack, and 1,000 messages from three senders in one group keep sequence numbers 1 to 1,000.)
Messages are written once and read mostly by conversation, newest first. A wide-column store (Cassandra, HBase) keyed by conversation ID and sequence number fits that access pattern.
Shard by conversation ID, not user ID. Sharding by user means every 1:1 message is stored twice (once for each person); sharding by conversation stores it once and keeps the whole conversation on one shard. (session clip at 38:08)
With time left, mention: group chats (fan out to members; cap very large groups), read receipts (just another small message type), media (upload to blob storage, send a link), end-to-end encryption, rate limiting (see how to design a rate limiter) and presence (online status) with heartbeats.
Chat messenger mock interview: sharding by conversation, WebSocket limits
Facebook Messenger / WhatsApp deep dive: WebSockets vs push, SQL vs NoSQL, ordering
SDE Skills is a volunteer-run 501(c)(3) nonprofit with free weekly system design sessions and mock interviews on Zoom. See the schedule or read how to prepare for a system design interview.