All posts
System Design Mastermind · Part 23
  • System design
  • Interview prep
  • Messaging
  • Delivery guarantees
  • Real-time

WhatsApp system design: chat, offline delivery and the three ticks

How to design WhatsApp in real interview order: connections and device copies as the numbers that matter, a light API over one long-lived connection, chat servers, a session registry and per-device offline queues built in passes, one message walked from send to read, a lab on acks, retries and duplicates behind the ticks, a lab on the reconnect storm after a lost zone, a lab on group and multi-device fan-out with end-to-end encryption, and what happens when each part fails.

24 Oct 2026 · 32 min read · interactive

Share

The 1-minute answer

Every phone (and each linked device) keeps one long-lived, encrypted TCP connection to a chat server; messages, acks, receipts and presence all travel on it. Messages are end-to-end encrypted, so the server routes envelopes it can't read. The phone gives each message an id before the first try and keeps it in an outbox until acked. The chat server stores a copy for every recipient device in a replicated per-device offline queue, and only then acks: that's the first tick. It looks up the recipient's chat server in a session registry and forwards; if the device is asleep, a push through APNs or FCM wakes it to pull its queue. The recipient's device saves, then acks; the server deletes the copy and sends the sender a delivered receipt: two ticks. Opening the chat sends a read receipt. Duplicates from retries are dropped by message id at both ends, so it's at-least-once on the wire, once on screen. Undelivered copies are kept up to 30 days; delivered ones are deleted, so history lives on the phones. Groups use Sender Keys (encrypt once, the server fans out), receipts are batched and folded, and clients back off with jitter so a lost zone doesn't become a reconnect storm.

How this page follows the interview

Each phase is a section below, in the order you'd present it. Click a phase for what to say, what to write, and the trap.

✅ Seen: said publicly (cited)🔶 Inferred❓ Unknown: state it as an assumption🧭 Interview choice

New to long-lived connections, queues or idempotency? Foundations F04 (APIs and real time), F10 (queues and event streams) and F11 (idempotency and exactly-once) cover the building blocks this page puts together.

Requirements and numbers

Agree the product and the two promises behind the ticks, then size it. Two numbers matter more than messages per second: device copies per message and connections open at once. Change any input: each number comes with the decision it forces.

Functional

  • 1:1 and group chats (groups up to 1,024)
  • Sent, delivered and read ticks
  • Messages reach offline devices when they come back
  • Up to five devices per account (a phone + four linked)
  • Photos, voice notes and video, by pointer
  • Online, last seen and typing

Non-functional

  • End-to-end encrypted: the server can't read messages
  • Nothing acked is ever lost
  • ✓ under 1 s; ✓✓ under 1 s when the recipient is online
  • Each message shown once, in order per chat
  • Light on battery and data

Out of scope (say it)

Voice and video calls, Status, payments, Channels, backups, search, spam detection in depth.

Capacity calculator

Every input is an assumption 🔶: say it out loud. Anchors: 100 billion messages a day (Meta, Oct 2020) ✅ TechCrunch 2020 = 2 billion users × 50. About 1 million phones per chat server in 2014 ✅ third party. Group share, sizes and offline time are teaching values; WhatsApp hasn't published them.

Three rules for this estimate
  1. A day is 86,400 seconds; size for the busiest hour (and New Year's Eve), not the average.
  2. One send, many copies. Every recipient device and the sender's own other devices get a copy.
  3. Little's law for queues. Copies waiting = copies/s × share offline × how long they wait.
They'll push on thisAnswer out loud, then open.

Core entities and the API

A device sends envelopes; the server stores a copy per recipient device and deletes it on ack. What they listen for: a client-made message id, an ack from every hop, receipts that are messages too, and media by pointer.

EntityKey fieldsNote
Request
Response

The ticks: what each one means

Each tick is an ack from a different hop. Tick what has happened and see what the sender's screen shows, and why.

What WhatsApp says

  • ✓ sent; ✓✓ delivered "to the recipient's phone or any of their linked devices"; blue: read. ✅ WhatsApp FAQ
  • Groups: the second tick appears when everyone has received it; blue when everyone has read it. ✅ WhatsApp FAQ
  • Read receipts off works both ways, but not for group chats or voice-note play receipts. ✅ WhatsApp FAQ
  • The clock means not sent yet, usually a connection problem. ✅ WhatsApp FAQ

Read ticks are blue in the app; this page shows them in its own teal.

They'll push on thisAnswer out loud, then open.

High-level design

Build it in passes and say why each box exists. Click any box to see what it does, what it owns, what's inside it and what you'd watch.

They'll push on thisAnswer out loud, then open.

Walk one message, box by box

Asha sends "Reached the station?" to Ravi, who has a phone and a laptop. Then a group message and a lost ack. Each step lights up the path and shows what goes over the wire, what's stored and how long it takes.

On the wire

Arrows show who calls whom, and the numbers give the order. Replies go back along the same line. Messages between two chat servers are drawn through the box they both belong to.

Keeping a phone connected

A connection that has to live for hours on a phone, across tunnels, sleep and deploys. These six details are what separates a demo from a product.

    Data and database choices

    The server is a queue, not a database: copies live until a device acks them, then they're deleted. The rest is small and hot (sessions, keys, groups) or big and separate (media).

    DataPickConsideredWhy not those

    The one rule to know: the send path

    # On the chat server, for one send from a device.
    # Illustrative; WhatsApp's own code isn't public.
    def on_send(dev, msg):
        if seen.contains(dev.id, msg.id):          # a retry
            return ack(msg.id, seen.ts(dev.id, msg.id))
        for copy in msg.copies:                    # one per target device
            queue[copy.device].append(             # replicated, ordered
                id=msg.id, sender=dev.id, ct=copy.ct, ttl=30*DAY)
        seen.add(dev.id, msg.id, ttl=3*DAY)
        ack(msg.id)                                # ✓  only now
        for copy in msg.copies:                    # best effort, live path
            srv = sessions.get(copy.device)
            if srv: srv.deliver(copy.device)       # pulls from the queue
            else:   push.wake(copy.device)
    
    def on_device_ack(device, seq):                # saved on the phone
        m = queue[device].delete(seq)
        receipts.send(m.sender, m.id, "delivered") # ✓✓

    Illustrative. The order is the point: dedupe, store, ack, then the best-effort live path. 🧭

    Why the queue is per device

    1. Multi-device means a copy per device. Each device has its own identity key, so each gets its own ciphertext. ✅ Meta 2021
    2. Each device acks on its own schedule. The phone can be online while the laptop sleeps for a week. 🧭
    3. Delete on ack keeps it small. "Once your messages are delivered, they are deleted from our servers." ✅ privacy policy
    4. A pointer per device works too. Messenger's Iris kept one ordered queue with a pointer per destination, advanced on each successful send. ✅ Meta 2014

    More database questions

    They'll push on thisAnswer out loud, then open.

    Deep dive: acks, retries and the ticks

    Networks lose messages and acks, servers crash, apps get killed. A sender can't tell a lost message from a lost ack, so it must retry, so copies can arrive twice. The design that survives this is store before ack, ack after save, dedupe by id. Pick a case, then switch a rule off and watch what breaks.

    Lanes: Asha's phone, the chat servers, the offline queue, Ravi's phone. Arrows are numbered in order; red ones are lost or a crash. 🧭 Teaching sequence, not WhatsApp's wire format.

    How many duplicates without dedupe?

    Each try can lose the message or the ack. The sender retries until it gets an ack.

    The rules this lab teaches

    1. An ack is a promise. Make it only once the copy is on replicated storage; then a crash means "deliver later", never "lost". 🧭
    2. Ack after save, not on arrival. The phone acks once the message is in its database; the server keeps its copy until then. 🧭
    3. Ids from the sender. Retries reuse the id; the server and the phone drop repeats. At-least-once plus dedupe looks like exactly-once. 🧭
    4. Never give up silently. After a few tries, keep it in the outbox with a clock and retry on every reconnect. ✅ WhatsApp FAQ (clock)
    They'll push on thisAnswer out loud, then open.

    Deep dive: a billion connections and the reconnect storm

    Holding connections is easy until many drop at once. Each reconnect needs a handshake, auth, a session write and a queue check, and refused attempts still cost the server. The chart shows attempts per second against what the surviving servers can accept. Pick a preset, then change the numbers.

    Top, log scale: reconnect attempts per second (dashed, averaged over a few seconds) and how many are accepted (teal), with the accept capacity as a line. Bottom: share of dropped devices back (apricot). Fluid model in 1-second bins; a refused attempt costs 10% of an accepted one. Teaching numbers. 🧭

    Three levers, in order

    1. Spread the retries. Exponential backoff with a random wait: "Always use randomized exponential backoff when scheduling retries." ✅ SRE book
    2. Refuse cheaply. Cap handshakes per server and refuse before the expensive part, with a reconnect delay hint. 🧭
    3. Leave room. The survivors of a zone outage must be able to hold everyone; you can't add servers during the storm. 🧭

    Real numbers to quote

    2012: WhatsApp tuned one FreeBSD/Erlang server from ~200K to over 2 million connections ("all contention fixes"), peaking at 2.8 million. ✅ Erlang Factory 2012

    2014: about 150 chat servers at ~1 million phones each, 150 million peak connections, deliberately run at half the earlier density. ✅ third party (HighScalability)

    They'll push on thisAnswer out loud, then open.

    Deep dive: groups and multi-device fan-out

    End-to-end encryption means a copy per device. For a group that can be a thousand copies per message, plus a receipt from each. Sender Keys move the fan-out to the server; folding moves receipts off the sender; membership changes become the cost. Pick a preset, then change the numbers.

    How the two schemes work

    1. 1:1 with multi-device: client fan-out. The sender encrypts the message separately for each of the recipient's devices and its own other devices. ✅ Meta 2021
    2. Groups: Sender Keys. Each member sends its sender key to every member pairwise once; each message is then encrypted once and the server fans the single ciphertext out. ✅ whitepaper 2016
    3. Removal: rotate. When a member leaves, every remaining member makes a new sender key before its next message. 🔶 Sender Keys design

    Numbers to quote

    Groups of up to 1,024 members since November 2022. ✅ WhatsApp blog

    A phone plus up to four other devices, each with its own identity key. ✅ Meta 2021

    Receipt folding isn't published by WhatsApp: the FAQ shows the group ticks, not how they're computed. ❓ say it as a choice

    They'll push on thisAnswer out loud, then open.

    A message's lifecycle

    On the sender's phone every message is a small state machine, shown as ticks. Click events to move it; ones that can't happen from the current state are disabled. Each event shows what fires across the system.

    NormalSomething went wrongGreyed out: not possible from the current state.

    Edge cases interviewers love

    They'll push on thisAnswer out loud, then open.

    Failure, monitoring and recovery

    A chat system fails in two ways: loudly (connections drop, sends hang at the clock) and quietly (✓ arrives but ✓✓ doesn't). Click a box to take it down: red is the failed part, amber is its blast radius. Each answer covers impact, degraded mode, the alert, automatic and manual recovery, and how you'd trace it.

    Tracing it back: an online recipient vs a phone in Doze

    Every span carries the message id (never the content). Times are seconds from tapping send. In the slow trace the recipient's phone is asleep: the push is sent at once, but the OS delays the wake-up.

    How one failure becomes three

    What you'd alert on (SLOs)

    SignalTargetAlert

    Incident playbook

      The toolkit

      Name the technique, then say where it goes in this design.

      They'll push on thisAnswer out loud, then open.

      Making it fast, and who owns what

      Server work takes milliseconds; the phone's network and its sleep decide the rest. Bars are sizing estimates, not measured figures.

      TeamOwnsPaged when…

      Senior follow-ups beyond the happy path

      Interviewers pick from these themes once the design is on the board. Have one concrete answer per theme, tied to this design.

      Practice ladder

      Real interviews go level by level. Answer out loud before opening each one. Levels 6–7 are where Senior becomes Staff.

      Sources

      Checked October 2026. Product behaviour is from WhatsApp's own pages (Help Center on read receipts, Privacy Policy on deleting delivered messages and keeping undelivered ones up to 30 days, the Communities post on 1,024-member groups) and Meta's engineering posts (multi-device, July 2021; Messenger's Iris queue, October 2014). Encryption details are from WhatsApp's April 2016 technical white paper (the current version's PDF couldn't be fetched for this run). Server numbers are from Rick Reed's 2012 Erlang Factory slides and a third-party summary of his 2014 talk (HighScalability), so they are old and used as orders of magnitude. The 100-billion-messages figure is Meta's, as reported by TechCrunch (Oct 2020). WhatsApp hasn't published its queue store, session registry or receipt aggregation; those parts are tagged as inferred or interview choices. Hello Interview is a third-party prep site, used only to cross-check what interviewers expect. All three labs use rounded teaching values.

      System Design Mastermind · Classics

      Series home

      All of Classics

      6 published · 4 comingThe problems almost every loop draws from.

      01

      Uber system design, reverse-engineered: from tap to pickup

      In-memory geo index sharded by map cell → rank nearby drivers by road ETA → offer to one driver with a 15 s timeout → accept with compare-and-set → push updates to both apps.

      30 min · interactive Preview
      12

      Rate limiter system design: fair limits at a million requests a second

      Check every request once in the API gateway → one atomic Lua script per request on the caller's shard of a sharded Redis (token bucket for per-second, window for per-day) → 429 + Retry-After, or forward with RateLimit headers → local cache for keys already over → each rule fails open or closed on purpose.

      30 min · interactive Preview
      23

      WhatsApp system design: chat, offline delivery and the three ticks

      One long-lived encrypted connection per device → the chat server stores a copy per recipient device in a replicated offline queue, then acks (✓) → session lookup, forward or push → the device saves and acks, the copy is deleted (✓✓) → a read receipt when opened. Client-made ids and dedupe at both ends, backoff with jitter on reconnect, Sender Keys for groups.

      You're reading this Preview
      26

      Ticketmaster system design: selling seats without double-booking

      Cached reads for browsing → a seat inventory with one row per seat, sharded by event → a hold is one conditional UPDATE (only if free or expired) with a 10-minute timer → pay with a client-made idempotency key → confirm only if the hold is still yours, plus an outbox for tickets. A waiting room admits fans at the rate booking can serve.

      32 min · interactive Preview
      29

      News feed system design: fan-out, celebrities and ranking

      Write each post once → fan-out workers push its id into active followers' capped Redis timelines → accounts above ~1M followers are merged at read time instead → the feed service gathers ~1,500 candidates, a light model trims them, a heavy model predicts actions, a weighted sum orders them → deletes and blocks are checked at read time, pages use a cursor.

      32 min · interactive Preview
      32

      Notification system design: push, email and SMS without spam, drops or duplicates

      One Notify API with an idempotency key → a router checks dedupe, preferences, caps and quiet hours, picks live devices → per-channel queues with a transactional lane apart from bulk → workers call APNs, FCM, email and SMS with priority, expiry and a collapse id, retry 429s with backoff and delete dead tokens → campaigns paced below the provider quota, OTPs fall back to SMS.

      32 min · interactive Preview
      ··

      Video streaming (YouTube / Netflix)

      Coming next
      ··

      URL shortener

      Coming next

      More posts