š§Ŗ Developer Blog: How WhatsApp Handles Real-Time Messaging (and Why Messages Say āWaiting for this messageā¦ā)

š 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:
Your app encrypts the message using Signal keys
It sends the encrypted blob through a WebSocket (MQTT) channel
The WhatsApp server:
Stores the message temporarily
Forwards it to the recipient's device (when online)
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. š
Subscribe to my newsletter
Read articles from Thalla Jayanth directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
