How WhatsApp Notifications Work Internally — A System Design Perspective

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:

  1. The Notification Service in WhatsApp’s backend detects that Raju is offline.
  2. 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" } }
  3. 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:

ComponentRole
Message ServiceHandles message routing between users
Notification ServiceSends push notifications via FCM/APNS
Encryption ServiceEncrypts and decrypts message payloads
Storage ServiceStores encrypted messages for offline users
Delivery TrackerTracks sent, delivered, and read states
User Presence ServiceDetermines 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

GoalHow WhatsApp Achieves It
Real-time deliveryPersistent sockets (XMPP/WebSockets)
Offline supportStored encrypted messages + push
SecurityEnd-to-end encryption keys per user
ScalabilityMicroservices + distributed queues
Low latencyGlobal servers + efficient routing
Battery efficiencyOS-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:

  1. Decouple message delivery and notification logic (use queues).
  2. Use push services (FCM/APNS) for offline or background delivery.
  3. Maintain persistent connections for real-time chat.
  4. Ensure reliability with retry, message persistence, and acknowledgment mechanisms.
  5. 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.


Leave a comment