Contents

System Design Interview: Design a Chat App Like WhatsApp | OfferBull

System Design Interview: Design a Chat App Like WhatsApp

“Design a chat app like WhatsApp.”

The “like WhatsApp” is the part that burns people. Five minutes later the board has calls, status, payments, stickers, and a box labeled encryption, and nobody has agreed how a 1:1 text message gets from one phone to the other. I’d stop that early. Ask what they actually want, then design that.

This is a full worked walkthrough of a design a chat application system design prompt: requirements and numbers, why 1:1 and group chat are different problems, WebSockets and the message store, delivery receipts, presence, fan-out, offline sync, then the follow-ups that usually arrive around minute 35. For the clock and the section order, use the system design interview template. The numbers, dialogues, and design choices below are illustrative interview-prep frameworks, not a claim about how any named messenger runs in production.

Requirements and the numbers I’d put on the board

Start with questions, not boxes. I’d lock three things before I draw: what we will build, what we won’t, and a few numbers that change the design.

A clarifying exchange might sound like this (illustrative):

You: “I’d treat this as 1:1 and group text chat, plus media as a side path. Multiple devices can wait unless you want them in scope. I’d leave voice and video calls, payments, and a full status product out unless you ask. End-to-end encryption is a follow-up I’d rather not invent in the first ten minutes. What scale should I assume?”

Interviewer: “Say 50 million daily users. Groups up to a few hundred members, and a few very large groups.”

You: “I’ll assume about 20 messages per user per day, mostly small text, 20 percent of users online at peak, and we keep messages for a few years. Delivery should feel instant when both people are online. A message can take a short time to land if the other person is offline. At-least-once delivery is fine if we can dedupe. Fair?”

I’d do the arithmetic out loud, with rounded figures. 50 million daily users times 20 messages is a billion messages a day, about 12,000 a second on average. A 3x peak, just as an interview assumption, puts us around 35,000 a second. If a text message plus metadata is about 200 bytes, a year of text is on the order of 70 terabytes, before indexes and a separate store for photos and voice notes. At 20 percent online, that’s about 10 million concurrent connections.

Those numbers already make a few decisions for me. The connection layer is a real problem. 10 million open sockets will not live on a handful of app servers. Writes at 35,000 a second are serious, but they are not “invent a new database” serious if we shard conversations. Media should not travel on the same path as a 200-byte text. And group fan-out, not 1:1, is where this design gets expensive, which is why I’d talk about 1:1 versus group before I start naming services.

I’d write the non-functional requirements in one line each: online delivery should feel instant, the service should survive the loss of a connection server, we can tolerate a short delay for offline users, and we will not claim exactly-once delivery. I’d also ask whether read receipts are in scope, because they add a write, a privacy question, and a fan-out of their own.

/images/posts/design-a-chat-app-system-design/one-to-one-vs-group.jpg Write 1:1 and group as two paths early. The hard part is the group, not the private chat.

1:1 versus group: the part that actually changes the design

A 1:1 message has one destination. A group message has many, and some groups are popular. If you draw one architecture and hope it covers both, you usually get a design that works for a private chat and falls over when someone posts in a 10,000-member group.

For 1:1, the talking version is simple. The sender’s client assigns a message ID, so retries don’t create duplicates. The request hits an API, the message is written to that conversation’s store, and then we try to push it to the other person’s open connection. If they are offline, we keep it for sync and maybe send a push notification so the phone wakes up.

Groups add fan-out. Copying the message into every member’s inbox is fine for a 20-person group. For a 10,000-member group, one send becomes 10,000 writes, and the sender is still waiting. I’d say that out loud, then split groups by size.

Small groups can still fan-out on write, through a queue, so the sender gets an ack after the message is durable, not after every inbox is updated. Large groups I’d treat more like a shared log: write the message once, and let members pull or receive a lightweight pointer. That trade will show up again if you also design a news feed: push work on write, pull at read time, or do a hybrid when some destinations are huge.

I’d cap the default scope: groups up to 200 members, plus a small number of large groups we treat differently. If they want a 10,000-member group in the base design, I’d still write once and fan-out asynchronously. If someone joins or leaves, I wouldn’t rewrite history; new members start from a join cursor.

Connections, delivery, and where messages live

I’d draw the connection layer next. This is a chat interview, not a CRUD API with a socket tacked on.

Each online device keeps a long-lived connection to a gateway server. WebSockets are the default I’d pick: bidirectional, cheap to push, easy to explain. Long-polling is the fallback if a client can’t hold a socket. Connection servers are stateful: they know which devices they hold. App servers can stay mostly stateless. You need a lookup for “where is user 42 connected right now?” so a message can be routed to the right gateway. An in-memory map on the connection service is enough for a first pass.

Don’t put 10 million sockets on the same process that writes the message store. Split them. The same instinct shows up in load balancing and traffic management: terminate the sticky connections in one layer, and keep the request path behind it boring.

The message API can stay small. POST /conversations/{id}/messages sends a client-generated message_id, the conversation, a type (text or a pointer to media), and a server timestamp, not one from the phone. GET /conversations/{id}/messages?after=cursor is the sync path. Delivered and read can be acks on the socket, or a small ack endpoint.

Delivery receipts are easy to over-design. I’d keep three states: sent (the server has the durable copy), delivered (at least one of the recipient’s devices got it), and read (the user opened it, only if receipts are in scope). Each of those is an event, not a chain the sender waits on. Unread counts can be updated from the same events, not by scanning a conversation every time the app opens.

I’d shard the message store by conversation_id, so a history fetch is one range read. A 1:1 chat can get a stable ID derived from the two user IDs; groups get their own. Replication covers durability and failover. Cache recent conversations and recent pages, not the full history. The caching strategies post covers the patterns. For how you’d split the store as it grows, see database sharding and replication.

Media is a side path. The client uploads the photo or voice note to object storage, maybe with a short-lived signed URL, and the chat message carries a pointer, a thumbnail, and a size. Push a 4 MB image through the same socket as text, and you stall everything else on that connection.

I would not promise a global order across all of a user’s chats. I’d promise a total order inside a conversation, with a server sequence number. The client can show a local echo, then snap to that sequence when the ack comes back. The client ID is also the dedupe key: if the network retries a send, the server returns the original message. That’s why I pick at-least-once. It’s an honest promise, and with client IDs it feels like once to the user.

/images/posts/design-a-chat-app-system-design/message-path.svg I’d draw this once, then zoom in on group fan-out. The send request should return after the message is durable, not after every inbox is updated.

Presence, fan-out, and coming back from offline

Presence looks small and then it writes too much. “Online now” and “last seen at 10:14” are not the same feature. I’d keep online/offline ephemeral and driven by the connection: a heartbeat, a short TTL, and a presence store that is not your message database. When the socket drops, the user looks offline after the TTL, not after a write to disk. Last-seen is optional, and it is a privacy setting. Some users will want it off, so don’t publish it to everyone by default without asking.

Once a message is durable, a worker looks up who should receive it. Online devices get a push on their connection server. Offline devices keep the message in the store, and may get a push notification as a wake-up, not necessarily the body, especially if you later add encryption. I’d put this on a queue so a slow or huge fan-out cannot block the send API. If you want more practice talking through that pattern, see message queues and event-driven architecture.

/images/posts/design-a-chat-app-system-design/popular-group.jpg A 10,000-member group is the follow-up hiding in the base prompt. Write once, fan-out in the background.

A popular group is where I’d spend leftover time. One message, 10,000 members, maybe 2,000 online. I would not loop 10,000 writes inside the send request. Write once to the group log, publish one fan-out job, and push to online members in batches. Offline members pick it up on sync. If the group stays huge and busy, members can pull from that shared log instead of each keeping a full private inbox. The cost: reads get heavier, and someone who left or was banned must be filtered out.

Offline sync is the part people skip. A device that was offline for twenty minutes asks for messages after its last cursor. A device that was offline for a week should not download a week of every group in one shot. Page it, recent conversations first, and load older history when the user opens a thread. If the cursor is so old that data has been archived, say so, and have a path to fetch it.

A buggy client, or a bot, can soak a group or open connection storms, so I’d cap sends per user and per group, and cap new connections from one device. The rate limiting and throttling post is the deeper version of that discussion. The same “don’t decorate the board” caution from system design mistakes to avoid applies here: a queue and a presence store should appear because a number forced them, not because they look serious.

Follow-up questions interviewers actually ask

They usually poke the design in the last ten minutes instead of starting a second problem. Short spoken answers you can practice, all illustrative:

“How do you order messages?” “Per conversation, with a server sequence number. I wouldn’t promise a global order across all of a user’s chats. The client can show a local echo, then reconcile when the server ack arrives.”

“Exactly-once or at-least-once?” “At-least-once. Exactly-once is a hard promise on a flaky mobile network. I’d have the client send a message ID and dedupe on that, so a retry doesn’t create a second copy.”

“A device was offline for a week. What happens?” “On reconnect it syncs from its last cursor, in pages, recent conversations first. I wouldn’t dump seven days of every group in one response. If some history has been archived, the client fetches that only when the user scrolls back.”

“What about read receipts and privacy?” “Delivered and read are events, not something the sender waits on. I’d make read receipts a setting, and I wouldn’t leak last-seen or read state if the user turned that off. Unread counts can be maintained from the same events.”

“Someone sends a message in a 10,000-member group.” “I wouldn’t fan-out 10,000 inbox writes on the request path. Write once to the group log, enqueue a fan-out job, push to online members in batches, and let everyone else catch up on sync. If the group stays that large and that busy, I’d treat it more like a shared log than 10,000 private inboxes.”

This prompt also sits on most “common questions” lists, including top FAANG system design questions. If they shrink the scope to a tiny 1:1 service, the same order still helps. The URL shortener walkthrough is a useful contrast: that problem is read-heavy, and this one is connection-heavy and fan-out-heavy.

Practice the talking version

A worked design on a blog is the easy half. In the room you still have to cut WhatsApp down to text chat, explain why a group is not just “1:1 with more users,” and keep going when someone says “can’t we just keep every socket on the app server?”

OfferBull is an AI mock interview app for iOS and Android. A voice interviewer asks questions aloud. You answer by speaking. Paste a job description or upload a resume for tailored questions. Follow-ups based on what you said and what’s on the resume. While you practice, you get answer suggestions and STAR structures. English and Chinese. It’s for rehearsal before a design interview, not a helper during one.

Start an AI mock interview

FAQ

Do I have to use WebSockets? They’re the default I’d pick for online push, and they’re easy to explain. Long-polling is a fine fallback if a client can’t hold a socket. The point is a connection layer you can address, not the specific protocol name.

How is group chat different from 1:1? Fan-out. A private message has one destination. A group message may have thousands, and the send path should not wait on every inbox write. Small groups can be copied out in the background. A very large group should be written once, then pulled or pushed as a pointer.

Should I design end-to-end encryption? Ask whether it’s in scope. If they want a first-pass chat system, I’d leave it as a follow-up: media and push notifications can’t carry plaintext the same way, and keys become their own service.

What if my interviewer wants a different scale? Redo the few numbers that change a decision, out loud. A million daily users might fit on fewer connection servers. A billion makes the gateway layer and large-group fan-out the center of the interview.


Practice This Out Loud

Tonight, if you can: set a 45-minute timer, close the notes, and talk through this prompt from requirements to one deep dive and one failure mode. Record it on your phone. On playback, check two things only. Did you split 1:1 from group chat and pick a delivery promise? Did you get to a popular-group or week-offline discussion before the timer ended? Then run the same prompt in a voice mock that pushes back with follow-ups, and close the app before any real interview. → Practice Now


Take Control of Your Career Path: