Skip to main content

Chat App: Requirements & High-Level Design

Editorial

Problem Statement

Design a messaging app like WhatsApp. People send text messages to one person or to a group of up to 1,024 members, and share photos, videos and voice notes. A message reaches an online recipient within a second; for one who is offline it waits, for up to 30 days. Every message is shown exactly once, in the order its sender wrote it. The sender sees when it was sent, delivered and read. A person uses a phone and up to four other devices at the same time. Messages are end-to-end encrypted: the servers carry them but cannot read them. People see whether a contact is online and when they were last seen. The app has 2 billion users.

The functional requirements below come from its verbs; the rest of the statement sets the non-functional ones.

Introduction

WhatsApp is the largest system of this kind, and it once published its numbers. In March 2014 its servers took in 19 billion messages a day and sent out 40 billion, for 465 million monthly users; they held 147 million concurrent connections, about a million on each of some 150 chat servers. In 2020 it passed two billion users and said it delivers roughly 100 billion messages a day.

Sending a message looks like the simplest thing a server can do: receive bytes, pass them on. What makes it hard is everything that goes wrong in between:

ChallengeWhy it is hard
A connection to every phoneHundreds of millions of devices stay connected at once. A message has to find the one server that holds its recipient's connection
Offline is normalPhones sleep, lose signal, run out of battery. A message has to wait for its recipient safely and arrive when they are back, however often the network drops in between
Exactly once, in orderNetworks lose acknowledgements, so everything is retried. A retry must not show a message twice or move it out of order
Many devices per personA message goes to every device of the recipient, and to the sender's own other devices
The server cannot readWith end-to-end encryption the servers route sealed envelopes. No server-side search, no content filter, no history on the server
GroupsOne message to a group of 1,024 people with five devices each is 5,119 deliveries, and every member must see the group's messages in the same order

In this design every device keeps one long-lived connection to a gateway, and a small registry records which gateway holds which device. Each device has a mailbox on the server: an ordered queue of everything waiting for it. Sending a message means writing it into the mailboxes of the devices it is for; the sender's first tick (✓) means it is stored. The gateway that holds a receiving device pushes it; the device stores it and acknowledges, and the mailbox deletes it. A device that was away reads its mailbox from where it left off. The sending phone encrypts every message once for each receiving device, so the servers never see the text. A group message is encrypted once and copied into every member's mailboxes by a fan-out service.

Related lessons: the building blocks are in WebSockets: The Two-Way Street, The 10K Connections Problem, L4 vs L7 Load Balancing (+ Sticky Sessions), Idempotency: Safe to Retry, Delivery Semantics: At-Most, At-Least, Exactly-Once, Calling Services Safely: Timeouts, Retries & Backoff and Queue Models: Broker (RabbitMQ) vs Log (Kafka) (Fundamentals of System Design), Sync vs Async Replication & Failover and Choosing a Shard Key (Data Systems at Scale), Heartbeats & Failure Detection, Ordering in Practice and Retries, Budgets & Retry Storms (Distributed Systems & Reliability), and Pattern: Real-time Updates, Pattern: Fan-out — Feeds & Timelines, Pattern: Handling Large Blobs and Kafka vs RabbitMQ vs SQS (System Design Interview Mastery).

Functional Requirements

We extract the operations from the verbs of the problem statement:

FR1 — Send and receive. A user sends a text message to another user. It appears on every device of the recipient and on the sender's own other devices. Sending the same message again, as a phone does after a timeout, never makes two.

FR2 — Offline delivery. Messages for a device that is offline wait on the server and arrive, in order, when it reconnects. A message waits up to 30 days and is then deleted.

FR3 — Message status. The sender sees one tick when the server has the message, two when it reached one of the recipient's devices, and two blue ones when it was read. In a group the second tick appears when every member has it.

FR4 — Groups. A user creates a group of up to 1,024 members, adds and removes members, and sends to it.

FR5 — Many devices. A user links up to four devices to their phone. Each one sends and receives on its own, including while the phone is off.

FR6 — Media. Users send photos, videos, voice notes and files.

FR7 — Presence. A user sees whether a contact is online or typing, and when they were last seen.

Out of Scope

  • Voice and video calls
  • Status updates, Channels and Communities
  • Registration, phone-number verification and finding which contacts use the app
  • Backups of a user's chats to their own cloud storage, and keeping history on the server (a staff-level topic in the Interview Guide)
  • Search: with end-to-end encryption it runs on the device
  • Payments, businesses and bots

Non-Functional Requirements

The rest of the problem statement gives the quality requirements:

  • "reaches an online recipient within a second" → Latency
  • "waits, for up to 30 days" → Durability and Retention
  • "shown exactly once, in the order its sender wrote it" → Correctness
  • "the servers carry them but cannot read them" → Privacy
  • "2 billion users" → Scale

One more follows from what the app is for, reaching people: Availability.

Latency

  • A message reaches an online recipient's device within 1 second at the 99th percentile
  • The sender sees the first tick within 500 ms

Availability

  • Sending and receiving: 99.99%, about 52 minutes a year. A gateway, a database server or a whole data-center zone can fail without users noticing more than a reconnect

Durability

  • A message the server has confirmed with a tick survives the loss of any one server, also in the second after the tick

Retention

  • A message is deleted from the servers as soon as every device it was meant for has it, and after 30 days if some device never comes back

Correctness

  • A message appears once on each device. One sender's messages appear in the order they were written. Every member of a group sees the group's messages in the same order

Privacy

  • The servers store and forward ciphertext only. They know who sends to whom, when and how much, but not what

Scale

  • 2 billion users: about 1.5 million messages a second and 630 million connected devices at the peak (estimated next)

Resource Estimation

What People Do

WhatsApp published one detailed set of numbers, in a talk by one of its engineers at Erlang Factory in March 2014. We take the shape of the traffic from it and scale it to our 2 billion users.

AssumptionValueBased on
Users2 billionthe problem statement (WhatsApp since 2020)
Messages sent a day per user41WhatsApp, 2014: 19 billion in a day for 465 million monthly users
Busiest second over the average second1.56×WhatsApp, 2014: 342,000 messages in at the peak, 220,000 a second on average
Deliveries per message sent2.1WhatsApp, 2014: 40 billion messages out a day for 19 billion in, because a group message goes out many times
Devices connected at once32% of usersWhatsApp, 2014: 147 million concurrent connections for 465 million monthly users
One envelope (an encrypted message with its routing)about 200 bytesa typical text is 36 bytes (the median of 55,835 real text messages); Signal's library makes 137 bytes of ciphertext of a 40-byte text; the server adds about 50 bytes of ids and times
WhatsApp's own numbers set the shape. March 2014, 465 million monthly users: the ratios we scale to 2 billion. Messages a second: in, 220 thousand on average and 342 thousand at the busiest second; out, 463 thousand on average and 712 thousand at the busiest second. 19 billion in and 40 billion out a day; 147 million concurrent connections. 41 messages sent a day per user (19 billion ÷ 465 million); the busiest second 1.56 times the average (342 thousand ÷ 220 thousand a second); 2.1 deliveries per message sent (40 billion out ÷ 19 billion in, because of groups); 32% of users connected at once (147 million ÷ 465 million). At 2 billion users: 82 billion sent and 172 billion delivered a day; about 1.5 million in and 3.1 million out a second at the peak.

Traffic

WhatA dayA secondAt the peak
Messages sent2 billion × 41 = 82 billion946,000~1.5 million
Deliveries (one per receiving device)82 billion × 2.1 = 172 billion2.0 million~3.1 million
Logins (devices connecting)~990,000 (WhatsApp, 2014: 230,000)

A check: in 2020, with two billion users, WhatsApp said it delivers roughly 100 billion messages a day. That lies between our 82 billion sent and 172 billion delivered.

Two of these numbers surprise people. The busiest second is only 1.56 times the average: the users live in every time zone, so the evening of one country is the morning of another. And the servers send out more than twice what comes in, and that was before linked devices: each one receives its own copy of every message too.

Connections

WhatCalculationResult
Devices connected at the peak2 billion × 32%~630 million (each online linked device adds one)
Gateways at a million connections each630 million ÷ 1 million~630
Gateways that survive the loss of one zone of three630 × 3 ÷ 2~950
Registry, one entry per connected device630 million × 126 bytes~80 GB of memory

A million connections on one server is WhatsApp's own figure: in 2014 each chat server held about a million phones, and in January 2012 WhatsApp reported one server holding over 2 million TCP connections with 42% of its CPU idle. What limits a gateway is memory and kernel settings, not a magic number. The spare capacity is the point of the last row: when a zone goes dark, its devices reconnect to the other two, and those must have room for them.

Storage

A messenger that deletes delivered messages stores only what is waiting. How much that is follows from Little's law: the number of envelopes waiting equals the deliveries per second times how long an envelope waits on average. In PostgreSQL a waiting envelope took 282 bytes with its index:

Average waitEnvelopes waitingStorage
10 seconds20 million5.6 GB
1 minute120 million34 GB
10 minutes1.2 billion337 GB
1 hour7.2 billion2.0 TB
1 day172 billion49 TB

The number of messages sent does not decide the storage; the time they wait does. WhatsApp's 2014 talk put it in five words, "Most messages picked up very quickly"; the average is pulled up by the phones that stay off for days, and the 30-day limit caps it.

Bandwidth

WhatCalculationResult
Text at the peak3.1 million deliveries × 200 bytes~610 MB/s, ~4.9 Gb/s
Media on a peak dayWhatsApp, Christmas Eve 2013: 146 Gb/s, scaled by users × 4.3~630 Gb/s

Text is cheap. Photos and videos are over a hundred times more traffic, which is why they travel through their own servers and a content delivery network, not through the chat connection.

Data Model

The servers keep very little: who has which devices, what waits for each device, and which sends they have already stored. The text lives on the devices.

On the Mailbox Servers

The tables are those the tests run, in PostgreSQL. They are split across servers by user_id, so all devices of one person live on the same server.

-- every device of every account on this shard, and the next position in its mailbox
CREATE TABLE devices (
  user_id   bigint   NOT NULL,
  device_id smallint NOT NULL,                -- 1 is the phone, 2 to 5 are linked devices
  next_seq  bigint   NOT NULL DEFAULT 1,
  PRIMARY KEY (user_id, device_id)
);

-- what waits for a device, in the order the device reads it
CREATE TABLE mailbox (
  user_id       bigint   NOT NULL,
  device_id     smallint NOT NULL,
  seq           bigint   NOT NULL,
  message_id    uuid     NOT NULL,            -- chosen by the sending device
  sender_user   bigint   NOT NULL,
  sender_device smallint NOT NULL,
  envelope      bytea    NOT NULL,            -- ciphertext: the server cannot read it
  stored_at     timestamptz NOT NULL DEFAULT now(),
  PRIMARY KEY (user_id, device_id, seq)
);

-- sends this shard has stored, so that a retry stores nothing
CREATE TABLE accepted (
  user_id       bigint   NOT NULL,
  sender_user   bigint   NOT NULL,
  sender_device smallint NOT NULL,
  message_id    uuid     NOT NULL,
  accepted_at   timestamptz NOT NULL DEFAULT now(),
  PRIMARY KEY (user_id, sender_user, sender_device, message_id)
);
  • devices holds each device's next_seq, the number its next envelope gets. Every device has its own sequence: its mailbox is an ordered queue that it reads from where it left off.
  • mailbox holds one row per envelope waiting for a device. The envelope is ciphertext, encrypted on the sending device for this device alone. A row lives until the device acknowledges it, at most 30 days.
  • message_id is chosen by the sending device, a random UUID. It is the message's name everywhere: in every envelope, in the retries, in the receipts, on every device. A counter would not do: it starts again after a reinstall.
  • accepted remembers for 30 days which sends this server has stored, so that a retry stores nothing new.

Elsewhere

DataWhereKeyLives
Which gateway holds a deviceRedisconn:{user_id}:{device_id} → gateway, connectionwhile the device is connected
Public keys of each device: identity key, signed prekey, a batch of one-time prekeyskey directoryuser and deviceuntil replaced; a one-time prekey is deleted when handed out
Groups and their membersgroup servicegroup, then memberas long as the group exists
Group messages before their fan-outKafka topic, keyed by groupgroupa few days, far longer than a fan-out takes
Last seenkey-value storeuseras long as the account
Photos, videos, files (encrypted)blob store, behind a CDNrandom id30 days

API Design

A device keeps one long-lived connection to a gateway: a WebSocket over TLS, a standard any browser can open. WhatsApp's phones use their own protocol inside an encrypted channel built with the Noise framework, which hides even who is connecting from anyone watching the network. The frames are shown as JSON; a real client sends a compact binary encoding.

Device → Server

Send a message. One frame carries one envelope per receiving device: the recipient's devices, and the sender's own other devices so that they show the message too.

{
  "type": "send",
  "id": "4f1c9b2e-8d7a-4c3e-9b1f-2a6d5e8c7b90",
  "to": "user:1290001",
  "envelopes": [
    {"user": "user:1290001", "device": 1, "ciphertext": "Mwohc2Fk…"},
    {"user": "user:1290001", "device": 2, "ciphertext": "MwogE1Rx…"},
    {"user": "user:1170042", "device": 2, "ciphertext": "Mwoh9fQa…"}
  ]
}

The server stores every envelope and answers with the first tick; for a group message the reply also carries the message's position in the group's log, by which every device orders the group:

{"type": "stored", "id": "4f1c9b2e-8d7a-4c3e-9b1f-2a6d5e8c7b90", "at": 1760433000123}

If the recipient linked or removed a device since the sender last looked, the server refuses the send and returns the devices the account has now. The sender fetches keys for the new device, encrypts again and resends with the same id; whatever was already stored is not stored again:

{"type": "devices_changed", "id": "4f1c9b2e-8d7a-4c3e-9b1f-2a6d5e8c7b90", "user": "user:1290001", "devices": [1, 2, 3]}

Read the mailbox. On every connect the device asks for what came after the last envelope it stored, then acknowledges up to the last one it has stored now:

{"type": "sync", "after": 8790}
{"type": "ack", "upto": 8812}

Receipts travel as envelopes, like messages: the receiving device sends "delivered" and later "read" for a list of message ids, to every device of the sender.

Presence. The device reports when the app comes to the foreground and goes to the background, since "online" means the app is open. While a chat is open, it asks for the other person's presence and reports typing:

{"type": "active", "on": true}
{"type": "watch", "user": "user:1290001"}
{"type": "typing", "to": "user:1290001", "on": true}

Server → Device

An envelope from the mailbox, in seq order:

{
  "type": "envelope",
  "seq": 8812,
  "id": "4f1c9b2e-8d7a-4c3e-9b1f-2a6d5e8c7b90",
  "from": "user:1170042",
  "from_device": 1,
  "ciphertext": "Mwohc2Fk…",
  "at": 1760433000123
}

Presence of a watched user: {"type": "presence", "user": "user:1290001", "online": false, "last_seen": 1760432400000}.

HTTPS

MethodPathDoes
GET/v1/keys/{user_id}The key bundle of each of the user's devices: identity key, signed prekey with its signature, and one one-time prekey, which the server deletes as it hands it out
PUT/v1/keysThe device uploads a new batch of one-time prekeys when it runs low
POST/v1/mediaUploads an encrypted file; returns its id
GET/v1/media/{id}Downloads an encrypted file, through the CDN
POST/v1/groupsCreates a group; PUT and DELETE on /v1/groups/{group_id}/members/{user_id} add and remove members

High-Level Design

We build the design up one requirement at a time.

1. One Server

The simplest chat server keeps every connection in memory, in a map from user to socket. A message from Alice is a lookup of Bob's socket and a write to it.

One server holds every connection in memory. A message is a lookup in a map; everything else breaks. Alice's phone sends "to bob: hi" to the chat server, which keeps a map in memory: alice → socket 7, bob → socket 9, carol → none. It pushes the message to Bob's phone. Carol is offline: a message for her has nowhere to wait. Three things break: size, about 630 million devices online at the peak while one server holds about a million; failure, when the server dies every connection and every message in its memory is gone; offline, Carol is not connected, so her message has nowhere to wait for her.

Three things break at once:

  • Size. One server holds about a million connections. At the peak we have about 630 million.
  • Failure. When the server dies, every connection goes, and so does every message it was holding in memory.
  • Offline. If Bob is not connected, the message has nowhere to go.

2. Gateways and a Registry

Connections move to a fleet of gateways. A load balancer gives each new connection to some gateway; it does not know who is connecting and does not need to. After the device has authenticated, the gateway writes one entry in a registry: device → gateway.

When Alice's message arrives, the message service looks up each of Bob's devices in the registry and asks those gateways to push it.

Gateways hold connections; a registry knows where. The message service looks up each device and asks its gateway to push. 1: Alice's phone connects through a load balancer to gateway gw-1. 2: gw-1 sends her message to the message service. 3: the message service asks the registry, in Redis, for Bob's devices: conn:bob:1 is on gw-7 as connection c-41, conn:bob:2 on gw-3 as c-88. 4: it asks gw-7 and gw-3 to push, and they push to Bob's phone and laptop. On connect, the gateway writes the entry, with an expiry it keeps refreshing. On close, it removes the entry only if it still names this connection.

The registry is a Redis hash per device, conn:{user_id}:{device_id}, holding the gateway and the id of this connection. The gateway refreshes it with an expiry while the device is connected, so the entries of a gateway that dies run out on their own. When a connection closes, the gateway removes the entry only if it still names that connection:

-- KEYS[1] = conn:{user_id}:{device_id}, ARGV[1] = the id of the connection that closed
if redis.call('HGET', KEYS[1], 'connection') == ARGV[1] then
  return redis.call('DEL', KEYS[1])
end
return 0

A plain DEL would be wrong. A phone that switches from Wi-Fi to mobile data often reconnects through another gateway before the first one notices the old connection is dead. The late DEL would then erase the new entry, and the phone would be connected but unreachable. We ran both versions: DEL left no entry, the script kept the new one.

What is still broken: a message for an offline device has nowhere to wait, and one that a gateway is pushing when it dies is gone.

3. A Mailbox for Every Device

The message service now stores first and delivers second. Each device has a mailbox, an ordered queue on a mailbox server. A message is written into the mailboxes of the devices it is for, and only then does the sender get its first tick. Delivery reads from the mailbox; a device deletes from its mailbox by acknowledging.

Store first, then deliver: a mailbox per device. Each device reads its own queue, in order, from where it left off. 1: Alice's phone sends the message to the message service. 2: the service stores one envelope in each of Bob's devices' mailboxes on the mailbox server (bob · phone holds 8810, 8811 and the new 8812; bob · laptop holds the new 3302), then answers "stored": Alice sees one tick. Bob's laptop is connected: 3: its gateway gw-3 reads the mailbox in order and pushes 3302 to the laptop; 4: the laptop stores it and acknowledges up to 3302, and the mailbox deletes everything up to 3302; 5: the laptop's receipt reaches Alice as two ticks, delivered to one of Bob's devices. Bob's phone is off: a push notification says only that there is mail; it carries no message. On connect, the phone asks for everything after 8809 and gets 8810, 8811 and 8812, in order, then acknowledges 8812.
  1. Alice's phone sends the message to the message service, through its gateway.
  2. The message service writes one envelope into each of Bob's devices' mailboxes, in one transaction, and replies "stored": Alice sees ✓.
  3. Bob's laptop is connected, so the registry names its gateway, and the service tells that gateway there is new mail. The gateway reads the laptop's mailbox and pushes the envelopes in order.
  4. The laptop stores them and acknowledges up to the last one: {"type": "ack", "upto": 3302}. The mailbox deletes everything up to 3302.
  5. The laptop sends a "delivered" receipt to Alice's devices: she sees ✓✓.

Bob's phone is off, so the message service sends it a push notification through Apple's or Google's service. It carries no message, only the news that there is mail; the phone wakes up, connects, asks for everything after the last envelope it stored (8809) and receives 8810 to 8812 in order. A push cannot carry delivery: Apple calls its service "best-effort", it "may reorder notifications", and for a device that is offline it keeps only one notification per app.

The mailbox is what makes delivery safe. A gateway can die while pushing: nothing was deleted, and the device reads the same envelopes again after it reconnects. The message waits as long as it has to, and leaves the server the moment every device has it. The Delivery Deep Dives show why each envelope has a number from its device's own sequence, how the device makes sure it shows each message once, and where the mailboxes live.

4. Many Devices, Encrypted End to End

Bob has a phone and a laptop; Alice has a phone and a tablet. Each device has its own keys, and the servers never see the text, so the sending device encrypts the message once for every device that must show it: Bob's phone, Bob's laptop and Alice's own tablet. WhatsApp calls this client fan-out.

One message, one envelope per device. The sending phone encrypts for every device that must show it. 1: the first time Alice writes to Bob, her phone fetches the keys of Bob's devices from the key directory, once. 2: it encrypts the text once for each device: bob · phone, bob · laptop and alice · tablet, her own other device, and sends the three envelopes to the message service. 3: the service checks the devices each account has now: bob 1 and 2, alice 2 (besides the sending phone); both match. It writes two envelopes on Bob's mailbox server, for his phone and laptop, and one on Alice's, for her tablet. If Bob linked a third device a minute ago, the server refuses the send with devices_changed, bob, [1, 2, 3]; the phone encrypts for the new device too and resends with the same message id.
  1. Alice's phone asks the key directory for the key bundles of Bob's devices, the first time it writes to him. With them it sets up an encrypted session with each device, even while Bob is offline.
  2. It encrypts the text once per session: three envelopes, three different ciphertexts.
  3. It sends them in one send frame. The message service writes Bob's two envelopes on Bob's mailbox server and Alice's tablet's envelope on hers.
  4. Each server checks that the envelopes cover exactly the devices the account has now. If Bob linked a third device a minute ago, it refuses the send with the new list, and Alice's phone encrypts for that device too and sends again.

Without that check, a message would silently never reach Bob's new laptop. With it, a newly linked device receives every message sent after it was linked. Its older history comes from Bob's phone, which encrypts a bundle of recent chats for it; the servers never had that history to give.

5. Groups

Encrypting a group message once per member device would cost up to 5,119 encryptions for a full group. Instead each member has a sender key for the group, which it gives once to every other member device over their encrypted sessions. After that, each message is encrypted once, and the same ciphertext goes to every member.

A group message is encrypted once. One ciphertext into the group's log; a worker copies it to every member. 1: Alice's phone encrypts the message once with her sender key and sends that one envelope to the group service. 2: the group service appends it to the group log, a Kafka topic keyed by group; once at least two brokers have it, Alice sees one tick, and the message's position, 41. 3: a fan-out worker reads the partition in order and writes message 41 into the mailbox of every member device, one transaction per mailbox server. One order: every device, the sender's too, orders the group's messages by their position in the log (40, 41, 42). A full group: 5,119 rows, 1,024 members × 5 devices, 722 KB; about 100 ms in one transaction, about 4 s with one per member, measured on one laptop.
  1. Alice's phone encrypts the message once with her sender key and sends {"type": "send", "to": "group:88231", …} with a single envelope.
  2. The group service appends it to a Kafka topic keyed by group id: all of a group's messages go to one partition, in one order. Once Kafka has it on at least two replicas (acks=all, min.insync.replicas=2), Alice sees ✓, and the reply tells her phone the message's position in the log.
  3. A fan-out worker reads the partition. For each member, it writes the ciphertext into every one of that member's device mailboxes, batched by mailbox server, and then notifies their gateways.
  4. A member's devices receive and acknowledge it like any message. Each sends a "delivered" receipt to Alice's devices; her phone shows ✓✓ when every member has it.

Every device orders the group's messages by their position in the partition, so all members see the same order. Writing the copies after the tick keeps a full group's 5,119 mailbox writes off the sender's wait; the log keeps the message safe until they are done.

6. The Whole Design

The whole design: a mailbox per device. Gateways hold connections; services fill each device's mailbox. Devices, a phone and a laptop, connect through a load balancer to about 950 gateways, which record who is where in the registry, a Redis map from device to gateway, and pass frames to the services: message, group and presence. The message service writes envelopes into the mailbox servers, which are split by user, each with a standby in another zone. The group service appends to the group log, from which a fan-out worker writes into mailboxes. The presence service keeps last seen. Over HTTPS and push: the key directory hands out one-time prekeys once; the media service puts encrypted files, uploaded once, in a blob store behind a CDN; Apple's and Google's push services wake a device that is not connected.
ComponentWhat it doesSized for the peak
GatewaysHold the devices' connections; authenticate; push envelopes; send heartbeats~950, a million connections each, a third to spare
RegistryDevice → gateway, with expiry~80 GB in a Redis cluster, replicated
Message serviceChecks device lists; writes envelopes into mailboxes; tells gateways; sends push notificationsstateless; ~1.5 million sends a second
Mailbox serversOne ordered queue per device; delete on acknowledgement; 30-day expiry~3.1 million envelopes a second; split by user, each split replicated
Key directoryEach device's public keys; hands out one-time prekeys onceread once per new conversation
Group service and KafkaMembers; one log partition per group; fan-out workersthe group share of the traffic
Presence serviceOnline, last seen, typing, for the people watchingchanges, not polls
Media serviceEncrypted files in a blob store, behind a CDN~630 Gb/s out at the peak
Push serviceWakes devices through Apple's and Google's servicesone per waiting device

The life of one message, end to end:

The life of one message, tick by tick: stored, then pushed, then stored on the phone, then deleted. A sequence across ALICE, MESSAGE SERVICE, MAILBOX, BOB'S GATEWAY and BOB'S PHONE. Alice's phone sends the message to the message service, which calls deliver() on the mailbox; the mailbox answers stored, and the service answers Alice stored: one tick. The service tells Bob's gateway there is new mail; the gateway reads the mailbox after 8811 and pushes 8812 to Bob's phone, which stores it and commits. The phone acknowledges 8812 to the gateway, which deletes everything up to 8812 from the mailbox. Bob's phone sends a delivered receipt to the message service, which passes it to Alice through her mailbox: two ticks; later a read receipt: two blue ticks.
  • ✓ appears when the message is stored in every mailbox it is for (or, in a group, in the group's log).
  • ✓✓ appears when one of the recipient's devices has stored it and sent its receipt; in a group, when every member has.
  • Blue ✓✓ appears when the recipient opens the chat and their device sends a "read" receipt.

The three Deep Dives that follow take the design apart: delivery (how a message is shown exactly once, where messages wait, the order they arrive in, and what happens when connections drop), then groups and encryption (end-to-end encryption, many devices, groups, presence, media and the size of the fleet).