🧪 Developer Blog: How WhatsApp Handles Real-Time Messaging (and Why Messages Say ā€œWaiting for this messageā€¦ā€)

Thalla JayanthThalla Jayanth
3 min read

šŸ” Ever seen this on WhatsApp?

"Waiting for this message. This may take a while."

It’s not a bug.
It’s encryption + real-time architecture working together, and sometimes waiting on each other.


🧱 The Tech Stack Behind WhatsApp’s Real-Time Magic

Here’s what powers messaging in a system like WhatsApp:

šŸ“” 1. WebSockets for Persistent Connection

  • WhatsApp keeps a WebSocket connection open between the client and server.

  • Unlike HTTP, which is request-response based, WebSockets are bi-directional and persistent.

  • This is how:

    • You see ā€œTypingā€¦ā€

    • Messages show "Delivered" and "Read" instantly

    • You receive notifications in real time

WhatsApp likely uses MQTT, a super lightweight messaging protocol over TCP, built for low-latency, mobile-friendly messaging.


šŸ›  2. Signal Protocol for Encryption

WhatsApp uses the Signal Protocol, which:

  • Generates session-based keys for every chat

  • Encrypts every message with a unique key

  • Requires devices to fetch and decrypt messages using those keys


šŸ’¬ 3. How Real-Time Messaging Works

Let’s say you send a message:

  1. Your app encrypts the message using Signal keys

  2. It sends the encrypted blob through a WebSocket (MQTT) channel

  3. The WhatsApp server:

    • Stores the message temporarily

    • Forwards it to the recipient's device (when online)

  4. Recipient’s device:

    • Retrieves the message

    • Decrypts using session keys

    • Shows it in the chat


🧵 4. Why ā€œWaiting for this messageā€¦ā€ Appears

You see this when:

  • The encrypted message arrives

  • But the device doesn’t yet have the decryption keys

This happens if:

  • The sender recently reinstalled WhatsApp

  • You just logged in on a new device

  • A view-once media was already opened elsewhere

  • Your linked device (like Web/Desktop) hasn't synced fully


šŸ—ƒ 5. What’s Running in the Background?

Behind this ā€œsimple chat,ā€ here’s what’s going on:

  • Rooms & Channels (to route messages to the right users/groups)

  • Message queues (to retry delivery when a device is offline)

  • Key verification & sync (to share encryption keys securely)

  • Real-time DB writes (to persist every chat event)

  • Authentication middleware (to verify session IDs for all devices)


āš ļø Bonus: Scaling to Millions of Users

Systems like WhatsApp also have to handle:

  • Rate limiting

  • Session management

  • Device authentication

  • Cross-device sync (for linked devices)

All this while ensuring messages never get stored unencrypted on servers.


🧠 Summary

That little ā€œtypingā€¦ā€ indicator or delayed message comes from a powerful blend of:

  • WebSockets for real-time messaging

  • MQTT for efficient transport

  • Signal Protocol for military-grade encryption

  • Database queues & replication for delivery

It’s not magic. It’s just really good engineering. šŸš€

0
Subscribe to my newsletter

Read articles from Thalla Jayanth directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Thalla Jayanth
Thalla Jayanth