Chat Service

Design the backend infrastructure behind a chat product — stateful connection servers, message storage, and group fan-out — for hundreds of millions of concurrent users.

00

Practice checkpoints

The requirements are open as a taste. From the numbers onward, the full guide opens in the app.

  1. 01
    Clarify scope
  2. 02
    Requirements + scale
  3. 03
    API + data modelUnlocks in the app
  4. 04
    Draw architectureUnlocks in the app
  5. 05
    Deep diveUnlocks in the app
  6. 06
    Trade-off decisionUnlocks in the app
01

Requirements that shape the design

Do not only state requirements. Ask for them. Each card pairs the design constraint with a clarification question you can say out loud before drawing the architecture.

Functional requirements

01What does this layer promise the product teams building on it?

Hold one long-lived socket per online device and deliver any message published to that user in under a second — receipts, inbox rules, and other product semantics build on top of this layer.

02One-to-one and group chat — same infrastructure?

Yes: a 1:1 chat is just a group of two — one routing layer serves both, and only the fan-out strategy changes with group size.

03Do we store history, or only relay live traffic?

Every message is persisted before delivery, and any client can range-scan a conversation’s history in time order.

04Is presence this layer’s job?

Yes, as derived state: connection servers already know which sockets are alive, so presence is aggregated from socket state — never a separate per-client broadcast firehose.

05Can we deploy new connection-server code without users noticing?

Yes: servers drain gracefully — announce, stop accepting, let clients reconnect elsewhere with jittered backoff — and no in-flight message is lost because persistence precedes delivery.

06What happens to a message when the recipient is offline?

It waits in the conversation partition: delivery on reconnect is a partition read, so the socket layer never buffers for absent users.

Out of scopeProduct-level delivery semantics — read receipts, typing indicators, per-user inbox ordering (the messenger fan-out sibling question) · Client-side behavior — on-device queueing, optimistic UI, local storage (the Chat App question) · Media pipeline — image/video upload, transcoding, CDN delivery

Non-functional requirements

01How many users are connected at once, and what does that force?

300M concurrent connections — the socket IS state, so this is a stateful fleet with a registry, not a stateless pool behind a load balancer.

02What latency counts as real-time here?

Under 500 ms sender-to-recipient in-region — which rules out polling and anything that parks messages behind batch layers.

03Can a message be lost?

No message loss: persist before acknowledging the sender, deliver at-least-once, and let clients dedup by message id.

04What write volume must the storage tier absorb?

Billions of appends a day — storage is write-optimized and partitioned by conversation, so a history scan never crosses partitions.

05A server dies holding a million sockets — how bad is that allowed to be?

A dying server is a bounded event: clients reconnect with jittered backoff, the registry evicts its lease in seconds, and the reconnect storm must not cascade across the fleet.

Keep asking — the interview is a conversation

Real interviews probe far more than a tidy list. These are the scope questions that separate candidates who interrogate the problem from those who recite it.

  • Are we designing the infrastructure layer only, or do you also want product semantics like read receipts and inbox ordering?
  • How large do groups get — dozens, or six-figure channels? The fan-out strategy hinges on that number.
  • How much history must be instantly scannable, and how old can a message be before slower storage is acceptable?
  • How often does this fleet deploy? Daily deploys justify serious drain machinery; quarterly ones do not.
  • Single region, or global? Cross-region replication changes where per-conversation ordering gets decided.
01

Unlock the full playbook for Chat Service

Numbers, architecture diagram, API and data model, deep dives, expected topics, self-check, whiteboard starter, and common mistakes unlock inside the app.

02

Numbers that force architecture decisions

Locked in the app

03

Architecture path

Locked in the app

04

API and data model

Locked in the app

05

Deep dive directions

Locked in the app

+Series

Practice the related series