Skip to content
All problems

Design a one-to-one and group chat system

breadth · 45 min · senior/staff

Setting

You're building the messaging backbone for a consumer chat app: one-to-one conversations, small group chats, delivery/read receipts, and a client that's frequently offline (mobile, spotty connectivity).

The ask

Design the system that lets a user send a message, delivers it to every recipient's device (online or not), and shows accurate delivery and read state.

Constraints & scale

  • ~50M daily active users, ~10B messages/day, groups up to 250 members
  • End-to-end delivery latency < 1 s p99 when both parties are online
  • Messages must never be lost and must arrive in a sane order per conversation, even across reconnects and multiple devices per user
  • Offline users must receive every message once they reconnect, without duplicates
  • Read receipts and typing indicators are best-effort and may be dropped under load — message delivery may not

What a strong answer covers

Requirements → estimates → API/data model → high-level diagram (connection layer, message store, fan-out) → 1–2 deep dives → trade-offs. Likely probes: how you fan out a group message, how a client resumes after being offline for days, and where exactly-once vs. at-least-once delivery applies.

A 45-minute plan

  1. 0-5 min · Requirements
  2. 5-10 min · Estimates/API
  3. 10-25 min · High-level
  4. 25-40 min · Deep dive
  5. 40-45 min · Wrap

What to cover, in order

  1. Requirements
  2. Estimates
  3. API/data model
  4. High-level diagram (connection layer, message store, fan-out)
  5. 1–2 deep dives
  6. Trade-offs

Where the follow-up questions go

Pick one of these for your deep dive before the interviewer picks for you.

  • How you fan out a group message
  • How a client resumes after being offline for days
  • Where exactly-once vs. at-least-once delivery applies

Key trade-offs

Decisions a strong answer weighs, and what pushes each one either way.

  • Push over a live connection or pull from a log. A persistent connection gives sub-second delivery to online users, but it is a delivery hint and not a record. A durable per-conversation log that clients read from a cursor gives correctness after disconnects. Most designs use both, and the argument is about which one is authoritative when they disagree.
  • Fan-out on write or on read for groups. Writing one copy of a message per recipient makes reads trivial and per-user state simple, but costs 250 writes for a large group message. Storing one copy per conversation and tracking a cursor per member is cheap to write and slightly more work to read. Group size and how often members are online push the choice.
  • Where ordering comes from. A per-conversation sequence number assigned by one owner of that conversation gives a clean total order, but concentrates writes for a busy group and needs failover. Client timestamps are easy and wrong whenever clocks drift or a user has several devices. Order is needed per conversation, not globally, which keeps the sequencer small.
  • Delivery guarantee and duplicates. At-least-once delivery with a client-generated message id and server dedup is the practical default. Exactly-once over a flaky mobile link is not achievable end to end, so say where the dedup lives and how long its window is.
  • Strong or best-effort metadata. Delivery and read receipts, typing indicators and presence are high volume and low value per event. Dropping them under load is acceptable by the problem statement. Messages are not, so they should not share a queue or a failure domain with the lossy traffic.

Common mistakes

What goes wrong most often on this problem, and why it hurts.

  • Using the socket as the only copy of a message. If the connection drops after the client sends but before the server persists, the message is gone and the sender may not know. Persist and acknowledge before treating a message as sent.
  • No per-recipient acknowledgement state. Without a record of what each device has received, you cannot resume after offline periods or avoid redelivering everything on reconnect.
  • Ordering by wall-clock time. Two devices and two servers disagree by hundreds of milliseconds, so replies can appear before the message they answer.
  • Treating multiple devices as an afterthought. Read state, delivery and history all have to be per device or per user in a way that stays consistent. Bolting it on later usually means a data model rewrite.
  • Sending group messages from the request path to every member. One slow or dead connection then delays the sender's acknowledgement and everyone else's delivery. Hand the fan-out to a queue.

Graded on

Requirements & scoping · Estimation · API & data model · High-level architecture · Deep dive · Scalability & performance · Reliability & consistency · Trade-offs · Operability · Communication & drive

Ready to run this one for real?

Try this problem free

Your first session is free. Sign in, and you land on this brief, ready to start.