System Design Playbook
10 · System designs100 users → 100M+ users13 min read

Design WhatsApp (real-time chat)

Deliver billions of messages a day in real time, keep them in order, show sent/delivered/read ticks and reach phones that are asleep. The core ideas: persistent connections, finding which server a user is connected to, a write-optimised message store and push notifications.

In one sentence

Each phone keeps a persistent connection to a chat server; a session map says which server each user is on; messages are stored until delivered and offline users are woken with push notifications.

A reference design: it covers what an app like this needs and follows how these companies have described their systems publicly, simplified to be learnable.

Requirements

Functional

  • 1:1 and group chats
  • Sent / delivered / read receipts, online and typing
  • Photos, video and voice notes
  • Works across devices and when offline

Non-functional

  • Real-time: sub-second delivery
  • Messages never lost, order kept per chat
  • Huge, write-heavy volume
  • Privacy: end-to-end encryption

Back-of-the-envelope estimates

MetricEstimate
Messages100B / day (public order of magnitude) ≈ 1.2M messages/s
Concurrent connectionsHundreds of millions of phones online at once
Message size~100 B of text + metadata; media goes to object storage
Connections per serverWith an efficient runtime, ~1M per box (WhatsApp famously did ~2M on Erlang)

Protocol and data model

Chat isn't request/response, so the API is a set of events over a WebSocket (or a custom protocol over TCP) instead of REST endpoints.

→ send      { chatId, clientMsgId, body | mediaRef }
← ack       { clientMsgId, msgId, ts }            // ✓ sent
← message   { chatId, msgId, from, body, ts }
→ delivered { msgId }   → read { msgId }          // ✓✓ and blue ticks

messages(chat_id, msg_id, sender_id, body, created_at)   PRIMARY KEY (chat_id, msg_id)
sessions: user_id → chat_server, last_seen              (in memory / Redis)

Architecture

Architecture
Scale
Follow a request
◱Ana's phonesender◱Bob's phonereceiver⇄Load balancerlong-lived sockets⚙Chat server AAna connected here⚙Chat server BBob connected hereϟSessions &presenceRedis⚙Push serviceoffline delivery⛁Cassandraby chat_id, time▣Media storageS3 + CDN◎APNs / FCMApple / Google push

Step by step · Send a message

  1. 01Ana types "Dinner at 9?" and hits send
  2. 02Receives it over Ana's WebSocket
  3. 03Appended to the chat's partition → ✓ (sent)
  4. 04Bob is online, connected to server B
  5. 05Pushes the message down Bob's socket
  6. 06Bob's phone acks → Ana sees ✓✓ (delivered)

At this scale · 1M users

A message store built for writes

  • ▸Messages in Cassandra, partitioned by chat and sorted by time
  • ▸A push service handles offline delivery and retries
  • ▸Photos and voice notes in object storage, served by CDN

Tap any box to see what it does.

Deep dive: delivering across servers

Connections are stateful: Ana's socket lives on server A, Bob's on server B. Server A needs to know where Bob is. A session store (user → server) answers that, and messages travel A → B through a pub/sub channel or direct RPC. If Bob has no session, the message stays in his inbox and a push wakes his phone.

  • Ordering: a per-chat sequence (or timestamp + id) keeps messages in order inside a chat; global order isn't needed.
  • Groups: the server fans a message out to each member (small groups), or members fetch from the group's log (large groups).
  • Storage: a wide-column store partitioned by chat_id turns "load this chat" into one sorted partition read. WhatsApp itself deletes messages once delivered and keeps history on devices.
  • End-to-end encryption (Signal protocol): keys live on the phones, so the server stores and forwards only ciphertext.

How it changes with scale

Architecture
Scale
Follow a request
◱Ana's phonesender◱Bob's phonereceiver⚙Chat serverWebSockets + API⛁PostgreSQLmessages▣Media storageS3 + CDN◎APNs / FCMApple / Google push

Step by step · Bob is offline

  1. 01Ana sends a message
  2. 02Bob has no open connection
  3. 03Stored as undelivered
  4. 04Apple/Google wake up the phone
  5. 05App reconnects and syncs pending messages

At this scale · 100 users

One server keeps every connection

  • ▸Phones keep a WebSocket open to one chat server
  • ▸Messages stored in PostgreSQL
  • ▸Offline users get a push notification (APNs / FCM)

Tap any box to see what it does.

UsersWhat you runWhy it changes
100One WebSocket server + PostgreSQL + APNs/FCMEveryone is on the same server: delivery is trivial
10KSeveral chat servers, LB, Redis sessions + pub/subUsers end up on different servers
1MCassandra message store, push service, media on S3 + CDNWrite volume and offline delivery need their own components
100M+Millions of connections per server, multi-region, E2E encryptionConnection count, cost per user and privacy at global scale

Key takeaways

  • 01Real-time chat needs persistent connections (WebSockets), not polling.
  • 02Connections are stateful: keep a map of which server each user is on.
  • 03Store messages in a write-optimised store partitioned by chat; deliver offline via push.
  • 04Receipts and retries rely on idempotent message ids.

Check your understanding

1 of 3

In a chat app like WhatsApp, how does each phone stay reachable in real time?

Security PlaybookNow attack it: threat-model this designFind the STRIDE threats in this architecture and pick the mitigations.↗