Have you ever wondered how WhatsApp notifies you instantly when someone sends a message — even when your app is closed? Let’s peel back the layers and look at how WhatsApp’s notification system actually works from a system design point of view.
🧠 The Big Picture
When you receive a new WhatsApp message like
“Ravi: Hey Raju!”
that notification travels through a complex, highly optimized system involving encryption, real-time messaging, and push infrastructure.
Let’s break it down step by step 👇
⚙️ 1. Message Creation — The Journey Begins
When Ravi sends a message to Raju:
- The WhatsApp client on Ravi’s phone encrypts the message using end-to-end encryption (E2EE).
- The encrypted payload is sent to WhatsApp’s Message Server through a persistent socket connection.
At this point, the message is unreadable to anyone — even WhatsApp itself.
📡 2. Message Routing — Finding the Recipient
The Message Server receives Ravi’s encrypted message and determines that it needs to reach Raju’s device.
- If Raju is online, the message is sent immediately via a persistent connection (using XMPP or WebSockets).
- If Raju is offline, WhatsApp stores the encrypted message temporarily in its Storage Service until Raju reconnects.
📬 3. Triggering a Notification — When the App Is Closed
If Raju’s app is in the background or not connected, WhatsApp triggers a push notification.
Here’s how it works:
- The Notification Service in WhatsApp’s backend detects that Raju is offline.
- It prepares a lightweight message payload — something like:
{ "to": "<Raju_Device_Token>", "notification": { "title": "WhatsApp", "body": "Ravi: Hey Raju!" }, "data": { "message_id": "abc123", "chat_id": "ravi_123" } } - It sends this payload to Firebase Cloud Messaging (FCM) for Android or Apple Push Notification Service (APNS) for iPhone.
☁️ 4. Push Infrastructure — Google & Apple Step In
Once WhatsApp sends the notification request:
- FCM/APNS looks up the device token (a unique ID representing Raju’s phone).
- They route the message through their global notification delivery networks.
- Raju’s phone receives it instantly — even if the app isn’t open.
This is possible because FCM and APNS maintain their own persistent channels with your device at the OS level.
🔔 5. Notification Delivery on Device
When Raju’s phone receives the notification:
- The OS wakes up WhatsApp’s background receiver.
- A notification appears on the lock screen or notification tray: “Ravi: Hey Raju!”
When Raju taps it:
- WhatsApp opens and establishes its secure socket connection to the server.
- The actual encrypted message is fetched and decrypted locally using Raju’s private key.
At this point, the two ticks ✅ (message delivered) appear on Ravi’s chat screen.
When Raju reads it, WhatsApp sends a “read receipt” (blue ticks 💙) back.
🔐 6. End-to-End Encryption (E2EE)
One of WhatsApp’s strongest features is end-to-end encryption.
- Messages are encrypted on Ravi’s device.
- Stored in encrypted form on WhatsApp’s server (if needed).
- Decrypted only on Raju’s device.
Even WhatsApp’s servers can’t see the content — they only know that a message exists and who it’s meant for.
🧩 7. Behind-the-Scenes Components
Here’s what’s happening under the hood:
| Component | Role |
|---|---|
| Message Service | Handles message routing between users |
| Notification Service | Sends push notifications via FCM/APNS |
| Encryption Service | Encrypts and decrypts message payloads |
| Storage Service | Stores encrypted messages for offline users |
| Delivery Tracker | Tracks sent, delivered, and read states |
| User Presence Service | Determines whether users are online or offline |
🧱 8. System Architecture Overview
Conceptually, it looks like this:
Ravi's Phone ──►(Encrypt Message) ──► Message Server ──► (Route + Store ) ──► Notification Service ──►(Push Notification) ──► FCM/APNS ──► Raju's Phone
⚡ 9. Why This Design Works So Well
| Goal | How WhatsApp Achieves It |
|---|---|
| Real-time delivery | Persistent sockets (XMPP/WebSockets) |
| Offline support | Stored encrypted messages + push |
| Security | End-to-end encryption keys per user |
| Scalability | Microservices + distributed queues |
| Low latency | Global servers + efficient routing |
| Battery efficiency | OS-managed push (via FCM/APNS) |
🚀 10. Key Takeaways for System Design Interviews
If you’re designing a notification system like WhatsApp’s, remember these principles:
- Decouple message delivery and notification logic (use queues).
- Use push services (FCM/APNS) for offline or background delivery.
- Maintain persistent connections for real-time chat.
- Ensure reliability with retry, message persistence, and acknowledgment mechanisms.
- Design for privacy with end-to-end encryption and minimal metadata storage.
🏁 Final Thoughts
WhatsApp’s notification system is a perfect blend of real-time communication, security, and scalability.
As a system architect, understanding how these layers interact — from event queues to encryption — is crucial for designing any large-scale, user-facing application.