WhatsApp System Design

Sending a Message

2 min read

Let's walk through the complete journey of sending a message.

Suppose Alice sends:

Hello!

to Bob.

Here's what happens.

The important observation is that the sender only waits until the server safely accepts the message.

Actual delivery happens asynchronously.

This keeps latency low even when recipients are temporarily unavailable.

The server stores the encrypted payload long enough to deliver it reliably. Chat history itself lives on devices after delivery — not as permanent readable history on the server.


Why Use Message IDs?

Every message receives a globally unique identifier.

Example:

msg_91F8A2C3

Instead of searching for message contents, every future operation simply references this ID.

Examples include:

  • Delete for Everyone
  • Edit Message
  • Read Receipts
  • Delivery Status
  • Reactions
  • Replies

The Message ID becomes the permanent identity of the message throughout its lifecycle.


Key Takeaways

✔ Persistent WebSockets enable real-time communication.

✔ Encrypted payloads are stored for durable delivery before fan-out begins.

✔ Server storage is temporary store-and-forward; chat history lives on devices.

✔ Queues decouple storage from delivery.

✔ Every message receives a unique identifier.

✔ Delivery happens asynchronously.


Next Chapter:

One Write vs 1024 Writes