Design Case StudiesAdvanced17 min read2 questions

Design a Chat System (WhatsApp / Slack)

Real-time messaging at scale. Connection management, per-conversation ordering, guaranteed delivery across flaky mobile networks, and group fan-out.

Covers: Connection tier, message storage and ordering, delivery receipts, offline sync, group chat fan-out, presence

Chat combines almost everything in this course: long-lived connections, ordering guarantees, at-least-once delivery with deduplication, fan-out, and a storage schema that must serve 'the last 50 messages in this conversation' in under 50 ms forever.

  • Functional: one-to-one and group chat; delivery and read receipts; offline delivery; message history; presence.
  • Scale: 500 M DAU, 40 messages/user/day ≈ 20 B messages/day ≈ 230,000 messages/s average.
  • Connections: ~50 M concurrent WebSocket connections at peak.
  • Latency: message delivered in under 500 ms when both parties are online.
  • Durability: a delivered message must never be lost. This is stricter than most systems in this course.
Filter
0/2 mastered
AdvancedmessagingorderingdeliveryAsked at WhatsApp, Slack

30-second answer

Assign each message a monotonically increasing sequence number per conversation, allocated server-side - never trust client clocks, because devices are skewed and users change time zones. Persist the message durably before acknowledging to the sender, then deliver at-least-once and let clients deduplicate by a client-generated message ID. On reconnect, the client sends its last-seen sequence number and the server backfills everything newer, so ordering and completeness both come from the sequence rather than from the transport.

Expertgroup chatfanoutstorageAsked at WhatsApp, Slack

30-second answer

Write the message once per conversation and give each member a cursor, rather than copying the message per member - 100,000 copies of every message is untenable in both write volume and storage. Store messages in a wide-column or sharded store partitioned by conversation ID and clustered by descending sequence, so 'the last 50 messages' is a single partition read. For very large groups, stop pushing to every member: deliver in real time only to members with an active connection and currently viewing, and let everyone else pull on open.

Showing 2 of 2 questions for design-a-chat-system.

Check your understanding

4 questions · no sign-up, nothing stored

0/4 answered
Question 1

1.Why must message ordering use a server-assigned sequence rather than client timestamps?

Question 2

2.How should read state be stored for a 100,000-member group?

Question 3

3.What should the messages table be partitioned by?

Question 4

4.When is a message considered reliably delivered?

Hands-on challenge

Build it - this is what you talk about in a deep-dive round.

Design the storage and delivery layer for a chat product

Support one-to-one chat, groups up to 100,000 members, offline delivery and multi-device sync.

Requirements

  • Design the message and cursor schema with partition and clustering keys, and justify both.
  • Write the send path showing deduplication, sequence allocation and persistence in one transaction.
  • Design the reconnect sync protocol including multi-device cursor reconciliation.
  • Define the group-size threshold at which delivery switches from push to pull, with reasoning.
  • Size storage, connection nodes and pub/sub fan-out with explicit arithmetic.

Stretch goals

  • Add full-text search over a user's history without scanning every conversation.
  • Design message deletion (for me / for everyone) consistent across all devices.