Design a chat application: the system design interview walkthrough
The request to design a chat application sounds like a CRUD app — save a message to a database, let the other person read it back. For two people refreshing a page that is exactly what it is. But the interview asks you to deliver each message to hundreds of millions of people the instant it is sent, in order, even when the recipient's phone is face-down in a pocket with the screen off — and that is a real-time routing problem, not a database write. Whether the prompt is phrased design WhatsApp, design Facebook Messenger, or just design a chat system, it is one of the most common system design interview prompts because the one-line brief hides a fleet of persistent connections and a delivery guarantee that has to hold at scale.
The round turns on two decisions. First, how a message typed on one phone reaches a specific other phone in under a second when the two devices are connected to different servers — a question of persistent connections and a registry that knows where each user's live socket lives. Second, how you never lose or misorder a message: one that is sent must be stored, delivered once, shown in the right order, and held safely until an offline recipient comes back online. This walkthrough follows the path a strong candidate draws on the whiteboard — requirements, estimate, API and data model, high-level design, then the deep dives — and at each step it names the follow-up the interviewer uses to tell a memorised answer from an engineer who understands the tradeoff.
How the chat application round is actually run
A chat application round runs about 45 minutes on a shared canvas — you draw the boxes and arrows while you talk, and the interviewer interrupts. It is a favourite because the one-line problem opens onto deep water fast: the moment you write "send the message," the question becomes over what connection, to which server, in what order, and what if they're offline — and every answer after that (persistent connections, routing, ordering, delivery guarantees, presence) compounds. Get the connection layer and the delivery guarantee clean and you have shown the whole system in one problem.
The interviewer rarely lets "store the message and the other user reads it" stand. "Both users are online — how does a message typed on one phone appear on the other in under a second, and which server does the recipient's connection even live on?" That question — real-time routing over persistent connections, not a request/response CRUD app — is the one a copied answer can never rehearse, and the one this round is really testing.
The rounds here are modelled on how the loop runs, not scraped from any candidate's recall. What matters for prep is the shape: a blank canvas, a clock, and a follow-up after every decision you make.
The five-step framework for any HLD round
Every high-level design answer fits the same spine. Say it out loud at the start so the interviewer knows you have a plan, then walk it:
- Clarify requirements — functional and non-functional, and what you are explicitly not building.
- Estimate — users, messages and concurrent connections, to justify every later choice.
- High-level design — the boxes and arrows: client, connection servers, chat service, message store, presence.
- Deep dive — the two or three decisions that actually decide this system.
- Follow-ups — bottlenecks, failure modes, and what you would change at ten times the scale.
What the debrief measures
The score is not "right or wrong design." A good HLD debrief reads on four dimensions, and every move below maps to one: problem solving (did you route a message to the recipient's connection server through a registry, not a database poll), communication (did you say why a persistent WebSocket over long-polling in a sentence), technical execution (per-conversation sequence IDs for ordering, client message IDs for dedup, an offline queue, presence by heartbeat), and time management (did you spend your 45 minutes on the connection layer and delivery, not on the emoji picker). Reading a walkthrough teaches the design; it does not teach you to deliver it on the clock while someone pushes back.
Step 1 — Requirements: what a chat application must do
Spend the first few minutes here. Jumping to boxes before you have scoped the problem is the fastest way to design the wrong system.
| Type | Requirement |
|---|---|
| Functional | Send and receive 1:1 messages in real time; group chat; online / last-seen presence; delivery and read receipts; correct message ordering within a conversation; offline delivery; push notifications when the app is backgrounded. |
| Functional (optional) | Media (images, voice notes), audio/video calls, message search, end-to-end encryption — name them, then scope most out for this round. |
| Non-functional | Low latency (sub-second delivery between online users); massive scale (billions of users, hundreds of millions of concurrent connections); high availability; durable storage (no message ever lost); correct ordering under retries. |
The sentence that earns points: "Storing a message is the easy part — the system is really a routing problem: holding hundreds of millions of persistent connections open and delivering each message to the right one in under a second, online or offline." Say that and you have framed the entire design before drawing a box.
Step 2 — Capacity estimation (back of the envelope)
Estimation here is about proving one thing: the hard axis is the number of persistent connections and routing a message to the right one, not message storage or compute.
| Quantity | Assumption | Result |
|---|---|---|
| Users | ~2B total, ~500M daily active | hundreds of millions of concurrent live connections |
| Messages | ~100B messages/day | ~1–2M messages/sec at peak |
| Fan-out | 1:1 is fan-out of 1; groups are small (capped) | fan-out is cheap — the scale axis is connections, not fan-out |
| Connections | each active user holds one persistent socket; a box holds ~tens of thousands | so you need thousands of connection servers, and a way to find the right one |
Two conclusions fall out, and you should say both out loud. First, the connection layer is the system — the design is bounded by how many persistent sockets you can hold open and how fast you can route a message to the box holding the recipient's socket, not by CPU or raw storage. Second, the message store is large but simple — append-only, sharded by conversation, write-heavy (a KV / wide-column store) — so you spend your minutes on the connection servers, the registry and the delivery guarantees, not on the store. You have now pointed the interview at the real deep dive before anyone asked.
Step 3 — API and data model
The public surface is thin — a client opens a connection and sends messages — so the "interface" is mostly the internal contract between the connection servers and the chat service, plus the tables that hold conversation state.
| Stage call | Operation |
|---|---|
connect() → WebSocket |
client opens a persistent socket to a connection server, which registers user_id → server in the connection registry |
send_message(conv_id, text, client_msg_id) |
the sender's connection server hands the message to the chat service |
route(conv_id, message) |
the chat service looks up recipients and forwards to their connection servers, or the offline queue |
ack(message_id, state) |
the recipient's device acks delivered / read; the state is propagated back to the sender |
The data model is thin — most state is the conversation log and the presence / connection maps:
| Entity | Notes |
|---|---|
message |
conversation_id (shard key), seq (per-conversation ordering), sender_id, client_msg_id (for dedup), body, created_at. |
conversation |
conversation_id, type (1:1 / group), member_ids, last_seq. |
offline_queue |
a per-user inbox of messages awaiting delivery while that user is offline; drained on reconnect. |
presence |
user_id → status, last_seen_at; a TTL key in Redis refreshed by heartbeats. |
connection_registry |
user_id → the connection server currently holding that user's live socket (Redis). |
Step 4 — High-level design: the message path
Now the boxes. The whole system is one path that carries a message from the sender's open socket to the recipient's open socket — and forks to a queue plus a push when the recipient is offline. Around that sit the pieces that make it ordered, durable and real-time:
- Client ⇄ WebSocket gateway / connection servers: each client holds one persistent connection to a connection server; the server registers the user in the connection registry so the system knows where to route.
- Chat service: receives a sent message, assigns a per-conversation sequence ID, writes it to the message store, and decides where it goes.
-
Message store: per-conversation, time-ordered, sharded by
conversation_id— append-only and write-heavy. -
Connection registry + router: maps
user_id→ connection server; the chat service forwards each message to the recipient's connection server, which pushes it down the open socket. - Message queue / fan-out: for group chat, fans one message out to each member; decouples the sender's single write from N deliveries.
- Presence service + push: tracks online / last-seen via heartbeats, and a push-notification service nudges offline recipients to reopen the app.
Say explicitly that a chat system is a routing problem, not a storage problem — the recipient's socket lives on a different box than the sender's, so every message is a lookup-then-forward across connection servers, and when the recipient is offline the path forks to a queue plus a push. Naming that shape unprompted is a signal the interviewer is listening for.
Deep dive: real-time delivery over persistent connections
This is the first decision that actually decides the round. A request/response API cannot push a message to a phone the instant it arrives — the client would have to poll, which is wasteful and slow. The senior answer is a persistent connection plus a registry that routes to it.
| Piece | What it does | Why it exists |
|---|---|---|
| Persistent connection (WebSocket) | the client holds one open, bidirectional socket to a connection server; the server can push a message down it the instant it arrives. | long-polling wastes connections and adds latency; you cannot hold hundreds of millions of sockets open on one tier without dedicated connection servers. |
| Connection registry | a fast store (Redis) mapping user_id → the connection server holding that user's live socket. |
the sender's message lands on one box, the recipient's socket lives on another — the registry is how the chat service finds the right box to forward to. |
The flow between them: a client connects to a connection server, which writes user_id → this server into the registry. To send, the sender's connection server hands the message to the chat service; the chat service persists it, looks the recipient up in the registry, and forwards the message to the recipient's connection server, which pushes it down the open socket. If the recipient is not in the registry — they are offline — the message goes to their offline queue and a push notification is fired. Delivery is therefore a lookup-then-forward, never a poll.
"The recipient is offline — where does the message go and how is it delivered later?" It is persisted to that user's offline queue and a push notification is sent; when they reconnect, their client pulls everything after its last-seen sequence number and the connection server resumes live delivery. Name both halves — the durable queue and the reconnect drain.
System Design
HLD · Messaging & realtime · 45 min
Design a chat application out loud, with follow-ups
Deep dive: message storage, ordering and delivery guarantees
This is the decision most candidates under-think. The happy path is easy; the follow-ups are always "what if they arrive out of order?" and "what if the network retries and sends it twice?"
Per-conversation sharding and ordering. Messages are stored per conversation, sharded by conversation_id so one conversation's log lives on one shard and stays append-only. Ordering is guaranteed by a monotonic per-conversation sequence ID assigned by the chat service — not by client timestamps, because device clocks drift and cannot be trusted. The receiver buffers incoming messages and renders them in seq order, so a message that arrives late still slots into the right place.
Delivery guarantees: at-least-once plus dedup. Networks drop, so clients retry, so duplicates happen. Every message carries a client-generated message_id; the store deduplicates on it, and writes are idempotent. At-least-once delivery plus idempotent, dedup-on-write storage makes delivery look effectively exactly-once to the user — you never silently lose a message, and you never show it twice.
Receipts, a small state machine. Each message moves sent → delivered → read: delivered when the recipient's device acks receipt, read when they open the conversation. These are tiny state updates propagated back to the sender over their open socket.
The offline queue. If the recipient is offline, the message is persisted in their per-user queue; on reconnect the client requests everything after its last-seen seq, and a push notification nudges them to reopen the app. The queue is what makes "delivered when they come back" a guarantee rather than a hope.
"Two messages arrive out of order — how do you guarantee the receiver sees them in order?" A monotonic per-conversation sequence ID assigned server-side defines the order; the client buffers and renders by
seq, never by client timestamps, so a late-arriving message still lands in its correct slot.
System Design
HLD · Ordering & delivery · 45 min
Defend ordered, at-least-once delivery out loud
Deep dive: group chat fan-out and presence at scale
Groups and presence change the shape of the problem. One message to a group is now N deliveries, and "who's online" is a signal every client wants about every contact — and the moment you scale either, two things need care.
For group chat, the standard answer is fan-out on write: when a message is sent, the chat service looks up the group's membership and forwards the message to each member's connection server (or offline queue). That works because consumer chat caps group size — a few hundred members, not a million — so the fan-out stays bounded and the receiver never has to poll. (A truly huge audience would flip to fan-out on read, but that is the live-stream problem, not this one.) For presence, each client sends a heartbeat to its connection server every few seconds; the presence service holds a TTL key per user in Redis, and last_seen_at is simply the time of the last heartbeat. A missed heartbeat expires the key and the user shows offline.
| Concern | Naive | Scaled |
|---|---|---|
| Group fan-out | sender writes one row, every member polls | fan-out on write to each member's connection server or offline queue — bounded because group size is capped. |
| Presence | every client polls "who's online" | heartbeats refresh a TTL key per user; last_seen is the last heartbeat; a sharded presence store holds it. |
| 9am reconnect storm | every reconnect broadcasts presence to all contacts | debounce and batch presence changes, subscribe only to the contacts a user has open, and shard presence by user. |
Repeat the real scaling axis: the system is bounded by concurrent persistent connections and the fan-out / presence chatter over them, not by message storage — so the connection servers, the registry and the presence sharding, not the database, are where this system lives or dies.
"A million users all come online at 9am — what breaks in your presence system?" The reconnect storm: every client re-establishes a socket and wants presence for all its contacts at once. You survive it by debouncing and batching presence updates, subscribing only to open conversations, and sharding the presence store so no single node takes the whole herd.
The follow-ups that decide the chat application round
Scan the probes from each deep dive and they rhyme. Master these five and you are ready for a version of the question that is not drawn exactly like this one.
- "Both users online — how does a message get there in under a second?" → A persistent WebSocket to a connection server, and a connection registry that routes the message to the box holding the recipient's socket. (problem solving)
- "The recipient is offline — where does the message go?" → Persisted to their per-user offline queue and drained on reconnect by last-seen sequence number, with a push notification to nudge them. (technical execution)
-
"Two messages arrive out of order — how does the receiver see them in order?" → A monotonic per-conversation sequence ID assigned server-side; the client buffers and renders by
seq, never by client clocks. (communication) -
"The network dropped and the client retried — won't it appear twice?" → A client-generated
message_idplus idempotent, dedup-on-write storage makes at-least-once delivery look exactly-once to the user. (technical execution) - "A million users come online at 9am — what breaks?" → The presence reconnect storm; debounce and batch presence, subscribe only to open contacts, and shard the presence store. (problem solving)
Each maps to a debrief dimension. Reading this list teaches you the answers; it does not teach you to deliver them while someone interrupts — that only comes from saying them out loud.
How to prepare: a one-week plan
You do not need fifty systems. You need this one cold and the framework automatic, so the next "design X" is just new nouns in the same five steps.
- Days 1–2: Learn the five-step framework until it is reflex. Do the chat app end to end on paper — requirements, estimate, data model, and the connect → send → route → deliver path.
- Days 3–4: Drill the real-time delivery deep dive: WebSocket vs long-poll, connection servers, the connection registry, and routing a message to the recipient's box. Say each tradeoff in one sentence.
- Days 5–6: Own storage, ordering and delivery — per-conversation sharding, sequence IDs, at-least-once plus dedup, receipts, the offline queue — and group fan-out plus presence. Answer each of the five follow-ups out loud.
- Day 7: A full timed 45-minute round, narrating the whole way, with someone (or something) interrupting. This is the rep that counts.
This post is the deep walkthrough behind one row of the broader Top 25 system design interview questions — once the chat app is automatic, the same spine carries the rest of the list.
Frequently asked questions
How do I design a chat application step by step?
Follow the five-step HLD framework. Clarify requirements (1:1 and group messaging, presence, delivery and read receipts, ordering, offline delivery, push — at hundreds of millions of concurrent connections); estimate to show the hard axis is the connection layer and routing, not storage; define the connect / send / route / ack contract plus the message, conversation, offline-queue, presence and connection-registry tables; draw the message path (client → connection server → chat service → message store, forwarded via the registry to the recipient's connection server, with a fan-out queue and a presence service); then deep-dive the decisions that matter — real-time delivery over persistent connections, storage and ordering and delivery guarantees, and group fan-out plus presence. Finish on the follow-ups about offline delivery and the reconnect storm.
How does a chat app deliver messages in real time?
Each client holds a persistent WebSocket connection to a connection server, which registers the user in a connection registry (user_id → which server holds their live socket). When a message is sent, the sender's connection server hands it to the chat service, which persists it, looks the recipient up in the registry, and forwards it to the recipient's connection server — which pushes it straight down the open socket. Delivery is a lookup-then-forward across connection servers, not a poll, which is what makes it sub-second for online users.
How does a chat application guarantee message ordering?
Ordering is per conversation, defined by a monotonic sequence ID that the chat service assigns on write — not by client timestamps, which drift across devices. Messages are stored sharded by conversation_id so one conversation's log stays append-only on one shard. The receiver buffers incoming messages and renders them in sequence order, so a message that arrives late over a slow network still slots into its correct position rather than appearing at the bottom.
How are messages delivered when the recipient is offline?
When the recipient has no live socket in the connection registry, the message is persisted in that user's per-user offline queue and a push notification is sent to nudge them to reopen the app. On reconnect, the client tells the server its last-seen sequence number and pulls every message after it, then resumes live delivery over the new socket. The durable offline queue is what turns "delivered when they come back" into a guarantee rather than a hope, and dedup on the client message id stops a retried message from arriving twice.
How does presence (online / last-seen) work at scale?
Each client sends a heartbeat to its connection server every few seconds; the presence service holds a TTL key per user in a store such as Redis, and last-seen is simply the time of the last heartbeat — a missed heartbeat expires the key and the user shows offline. The hard part is scale: when a million users reconnect at once (say 9am), the reconnect storm floods the presence system. You survive it by debouncing and batching presence updates, subscribing a client only to the contacts it actually has open, and sharding the presence store by user so no single node takes the whole herd.
How do I practise a system design interview out loud?
Reading a walkthrough is not the same as defending a design while someone interrupts. On Zynter, the HLD track runs live voice rounds modelled on how real system design loops run — you talk through a shared design on the canvas, and a voice interviewer pushes with the follow-ups above one at a time, then gives you a debrief on problem solving, communication, technical execution, and time management. The score is a practice signal, not a hiring decision.
Practise it on Zynter
You can read every hop. The round is won on the connection layer and the delivery guarantee.
Pick the Chat Messenger round, draw the message path on the canvas, and defend it out loud to a voice interviewer that keeps asking "where does the message go when the recipient is offline?" and "how do you guarantee the receiver sees them in order?" — then read the debrief. Zynter.ai is on-demand mock interviews modelled on real company loops, with 150+ rounds across 20 companies including the HLD system design track (Sep 2026).
Practise the Chat Messenger round →
Browse all interview tracks




Top comments (0)