Skip to the post

How WhatsApp works: the system design behind a message

WhatsApp system design explained simply: open connections, how a message is numbered, stored and routed, offline phones, and how the ticks work.

· 10 min read · High-level design (HLD)

You type "on my way" at a bus stop and tap send. Before you've put your phone back in your pocket, your friend's phone buzzes in another country. One grey tick, then two, then they turn blue. It feels instant and simple. Behind it is one of the most asked questions in interviews: WhatsApp system design.

WhatsApp hasn't published its full design, so this post does what an interviewer asks you to do: build a chat app that works the same way, step by step, with numbers. We'll follow one message from your thumb to your friend's screen, then look at the part most people get wrong, the ticks.

How big is WhatsApp?

Big enough that every simple idea breaks. In late 2020, Mark Zuckerberg said people send about 100 billion WhatsApp messages a day. That's over a million messages every second, on average.

For a design you can reason about, we'll use smaller example numbers, the kind you'd pick in an interview:

  • 500 million people use the app each day, and each sends about 40 messages.
  • That's 20 billion messages a day. Divide by the 86,400 seconds in a day and you get about 230,000 messages a second, and around three times that at the evening peak.
  • At about 200 bytes a message, that's roughly 4 TB of new messages every day.

Keep the 230,000 in mind. It decides almost everything that follows.

How does WhatsApp keep every phone connected?

Here's the first problem. How does your friend's phone find out a message is waiting?

The obvious answer is to ask. Every few seconds the app calls the server: "anything new for me?" Have a guess: if 100 million phones are online and each asks every 5 seconds, how many requests a second is that?

It's 20 million requests a second, and almost every answer is "no, nothing new". You'd be running a huge fleet of servers to say "nothing" over and over. And a message could still sit waiting for up to 5 seconds.

Two ways to get new messages. Asking every 5 seconds: 100 million phones make 20 million requests a second, almost all answered with nothing new. Holding one connection open: the server writes to the phone only when a message arrives.
Asking every 5 seconds vs holding one connection open

So chat apps turn it around. Each phone opens one connection and keeps it open, often a WebSocket or a similar long-lived link. Think of it as a phone call that never hangs up. Nobody speaks most of the time, but the moment there's something to say, the server says it, with no waiting.

The servers that hold these connections are called gateways. A gateway does very little work per phone. It mostly sits and waits. So one machine can hold a lot of them. Back in 2012, WhatsApp's engineers wrote that they had passed 2 million connections on a single server, using Erlang on FreeBSD. In a design today you'd plan more carefully, say 100,000 phones per gateway. Then 100 million phones online need about 1,000 gateways, and you'd run extra so that losing a data centre doesn't overload the rest.

Make sense? Good. Now let's send something.

What happens when you tap send?

Let's call you Alice, and your friend Bob. Alice's phone already holds a connection to one gateway, and Bob's phone holds one to a different gateway. Here's the trip, one step at a time.

1. Alice's gateway writes the message to a log. The log is an append-only list kept on several machines, something like Kafka. Messages are grouped by conversation, so everything in the Alice and Bob chat lands in the same place, in the order it arrived. As soon as the log has safely stored the message on at least two machines, Alice's phone shows one grey tick. That tick means "the server has it, and it won't be lost".

2. The chat service gives it a number. Each conversation has exactly one owner at a time, a chat service process that reads that part of the log. The owner gives the message the conversation's next number, say 42, and saves it in the message store.

Why number it here, and not use the time on Alice's phone? Phone clocks can be minutes off. If Alice's clock runs fast and Carol's runs slow, a group chat would show their messages in a different order on different phones. One owner handing out 42, then 43, then 44 gives every phone the same order.

3. The message store keeps it, sorted by conversation. With 230,000 new messages a second, one database server can't keep up. Most designs pick Cassandra or a similar wide-column database, spread over many machines by conversation, with each conversation's messages sorted by number. "Show me this chat, after message 40" then reads one place, already in order.

4. The routing map says where Bob is. When Bob's phone connected, its gateway wrote a small entry in a fast in-memory store such as Redis: "Bob's phone is on gateway 17". The owner looks that up and sends the message to gateway 17. Only gateway 17, not all thousand.

5. Bob's gateway writes it down his connection. Bob's phone saves it and answers "delivered up to 42". Alice sees two grey ticks.

The path of one message: Alice's phone, her gateway, a log kept per conversation, the chat service that numbers it 42 and saves it in the message store, a routing map that says which gateway holds Bob, then Bob's gateway and Bob's phone.
The path of one message, from Alice's phone to Bob's

Notice what each part does. The gateway holds connections. The log keeps the order and makes sure nothing is lost. The chat service numbers. The store keeps everything. The routing map finds people. Each part has one job, so each can grow on its own.

What if Bob's phone is offline?

Bob's phone is in airplane mode on a flight. What happens to message 42?

Nothing is lost, because the message is already in the message store. The routing map has no entry for Bob, so there's no gateway to send it to. Instead, the chat service hands the message to a notification service, which sends a push notification to Bob's phone through Apple or Google.

That push is a doorbell, not the delivery. It says "you have a message" and maybe shows a preview. When Bob lands and opens the app, his phone reconnects and asks the store for everything in each chat after the last number it has: "after 41, please". It gets 42 and anything else that arrived while he was away.

When Bob's app is closed: the message waits in the message store, a push notification goes through Apple's or Google's push service as a doorbell, and when Bob opens the app it asks for everything after number 41.
When Bob's app is closed: a push as a doorbell, then catch up from the store

Pax asks: Why not just keep the messages on the server and wait until Bob opens the app? Why bother with a push at all?

Because without the push, Bob has no reason to open the app. The message is safe in the store either way. The push is only there to tell him it's waiting. It's also why a lost push does no harm: the next time the app opens, it catches up by number anyway.

That "after 41" trick does a lot of quiet work. A phone that drops off Wi-Fi in a lift, a gateway that restarts, a push that never arrives: in every case the phone sees a gap in the numbers, or reconnects, and asks for what it missed. The connection makes messages fast. The numbers make sure none of them go missing.

How do WhatsApp's ticks work?

WhatsApp's help pages describe three states. One grey tick means the message was sent. Two grey ticks mean it reached the other phone. Two blue ticks mean the other person read it.

The first one is easy, as we saw: the log stored it safely. The other two are the interesting part. How would you store them?

The first idea most people have is a receipt for each message: "Bob got message 42", "Bob read message 42". Let's check the cost with our numbers. Two receipts per message, at about 50 bytes each, is 20 billion × 2 × 50 bytes, about 2 TB of receipts every day. And that's for one-to-one chats. In a group of 50, every message would need receipts from 49 people.

The better idea uses the numbers we already have. Since messages arrive in order, "delivered up to 43" says the same thing as receipts for 1 through 43. So each person in each chat needs just two numbers:

  • delivered up to: the highest message number this person's phone has saved
  • read up to: the highest number they've actually seen on screen
The ticks as two numbers per person per chat: delivered up to 43 and read up to 41. Messages 42 and 43 show two grey ticks; message 41 and older show blue.
Ticks as two numbers per person per chat: delivered up to and read up to

When Bob opens the chat, his phone sends one small update, "read up to 43", and every message up to 43 turns blue on Alice's screen. One update covers ten unread messages as easily as one.

What does it cost? Say 2 billion people, each in about 50 chats. That's 100 billion memberships, each holding two 8-byte numbers: about 1.6 TB in total. That total doesn't grow with every message sent. It only changes when people join chats. Compare that with 2 TB of new receipts every single day.

Way to store ticks Storage Grows with
A receipt per message per person ~2 TB a day (example numbers) Every message sent
Two numbers per person per chat ~1.6 TB in total New chats only

In a group, a message turns blue for the sender once the lowest "read up to" among the members has passed it. It's the same two numbers, just compared across the group.

How do group chats work?

Groups add one more question. When Alice writes to a group of 600 people, does the chat service send 600 copies?

It doesn't need to. Say 150 of the 600 are online right now, connected through 120 different gateways. The chat service looks up those members in the routing map with one batched request, then sends the message once per gateway, not once per person. Each gateway hands it to every member it holds. That's about 120 sends instead of 600, and nobody's phone talks to the database at all. The members who are offline get a push and catch up by number later, the same way Bob did.

Very large groups go a step further. Gateways subscribe to the group itself, so one message goes out once to every interested gateway. The exact cut-off is a design choice, and a good thing to say out loud in an interview.

Where you've met this design

The same building blocks show up wherever people chat:

  • Discord has written twice about storing its messages: in 2017 on Cassandra, grouped by channel and sorted by time, and in 2023 about its move to ScyllaDB, a Cassandra-compatible store, as it reached trillions of messages.
  • Slack has described its real-time system: phones and laptops hold a WebSocket to gateway servers, and channel servers send each message to every gateway that has someone in that channel.
  • WhatsApp itself protects message contents with end-to-end encryption based on the Signal protocol, so servers route messages they can't read. That's why it can still number, store and route a message: those steps only need to know who it's for, not what it says.

What interviewers ask next

Once you've drawn the send path, expect follow-ups like these. Try answering each one before you look anything up:

  • Bob has a phone and a laptop. How does a message reach both, and how does Alice's own laptop show what she sent from her phone?
  • The chat service that owns a conversation crashes halfway through. How do you avoid losing a message, or numbering it twice?
  • A whole data centre goes down at the evening peak. What happens to the millions of phones that were connected to it?

The full guide, Design a chat app (like WhatsApp or Messenger), answers each one, with the numbers to use and what to say in two minutes.

Recap

A chat app at WhatsApp's scale works because each part has one job. Phones hold an open connection to a gateway instead of asking every few seconds. A log keeps each conversation's messages safe and in order, one owner numbers them, and a store split by conversation keeps them all. A routing map finds the right gateway, a push wakes a sleeping phone, and the numbers let any phone catch up on what it missed. The ticks are the same numbers again: "delivered up to" and "read up to", two per person per chat.

Sources (8)
Free weekly email

One interview idea a week

A 3-minute read: one question interviewers ask, an everyday picture, the real numbers and what to say.

Check your inbox. If that address is new here, a link to confirm it is on its way. Tap it, and the first email comes within a week.

That address didn't look right. Check it and try again.

We couldn't sign you up just now. Please try again in a few minutes.

One email a week. Unsubscribe with one click from any email. Privacy

More from the blog

All posts