Skip to Content

What messaging system does WhatsApp use?

WhatsApp is a popular messaging app used by over 2 billion people worldwide. It allows users to send messages, photos, videos, documents and make voice and video calls. WhatsApp uses the Internet to send messages and media between users. But what underlying messaging system does WhatsApp rely on to deliver messages quickly and reliably around the world?

WhatsApp’s Messaging System

WhatsApp uses a messaging protocol called the Extensible Messaging and Presence Protocol (XMPP) to handle all messages sent through the app. XMPP, previously known as Jabber, is an open technology standard for real-time communication over the Internet. It enables the near-real-time exchange of structured data between any two or more network entities.

Some key features of XMPP:

  • Open source – XMPP is not owned by any single organization. It is an open standard that anyone can implement and innovate on.
  • Decentralized – There is no central server that all traffic flows through. Users connect from client to client.
  • Secure – XMPP supports SSL/TLS encryption for security.
  • Extensible – XMPP can be extended to add new features or capabilities.
  • Interoperable – It enables diverse systems and applications to exchange messages seamlessly.
  • Near real-time – XMPP enables fast message delivery with little delay.
  • Presence – It allows users to see who is online/available and users can set their status.

XMPP handles the core messaging functionality like sending and receiving messages, delivering read receipts, handling group chats, and indicating when a user is typing. This allows WhatsApp to provide a seamless messaging experience across devices and networks globally.

How Does XMPP Work?

XMPP works using a client-server architecture:

  • Users download a client app like WhatsApp to their device.
  • The client connects to a central XMPP server over the internet.
  • Users can discover other users by their JID or address like [email protected].
  • When User A wants to message User B, the XMPP client encrypts the message and sends it to the server.
  • The server routes the message to User B based on their address.
  • User B receives the message on their client which decrypts it for reading.

This is a simplified overview of how XMPP handles messaging end-to-end. The protocol handles additional functions like presence, roster management, security, extensions, and more.

Key XMPP Servers Used by WhatsApp

WhatsApp operates its own custom XMPP servers to handle all messaging traffic globally. Some of the key servers include:

  • messenger.whatsapp.com – Primary global server cluster that routes messages between users.
  • msgstore.whatsapp.com – Interface to message database storage.
  • w3.whatsapp.com – Multi-media file server for photos, videos, audio.
  • r.whatsapp.net – Remote server cluster for connectivity.

These servers are scaled massively to handle the enormous volumes of messages sent daily on WhatsApp, which exceeds 65 billion!

Message Routing

When User A sends a message to User B, how does WhatsApp route it efficiently? WhatsApp uses intelligent algorithms to route each message optimally.

Some key principles of WhatsApp message routing:

  • Uses distributed hashes for message addresses which allows scalability.
  • Employs locality awareness, messages are routed to geographically closer servers.
  • Does not rely on a central server, uses mesh topology instead for redundancy.
  • Uses end-to-end encryption, messages are encrypted before routing for security.
  • Supports TCP stream multiplexing which reduces latency.
  • Implements store and forward mechanism in case of network issues.

These approaches allow WhatsApp to reliably achieve millisecond message delivery speeds globally despite its massive scale.

Media Transfer Protocol

In addition to text messages, WhatsApp also has to transfer large media files like photos, videos and documents. It uses a custom Media Transfer Protocol to transfer media:

  • Uses HTTP stack for reliable transfer.
  • Encrypts media files using AES-GCM encryption.
  • Employs QUIC transport layer protocol developed by Google for faster transfer.
  • Uses Reed Solomon forward error correction codes to handle packet loss.
  • Allows transfer resume in case of network failure.
  • Implements media bundling to reduce handshake overhead of small files.

Thanks to these optimizations, WhatsApp provides fast and reliable media transfer speeds even on slow networks.

Group Messaging

WhatsApp also relies on XMPP extensions to handle group chats which have additional complexity versus one-on-one messaging.

Some key aspects for WhatsApp group messaging:

  • Every group has a unique JID for addressing messages.
  • Only group admins can modify group membership.
  • Messages are replicated and sent point-to-point to every group member individually.
  • Uses optimization like binary trees to send messages efficiently.
  • Implements conflict resolution logic in case of concurrent updates.
  • Group metadata is replicated asynchronously to members.

These mechanisms allow WhatsApp to scale to groups with 256 participants.

End-to-End Encryption

WhatsApp deploys the Signal Protocol for end-to-end encryption of all messages and calls:

  • Uses Curve25519 algorithm for elliptic curve digital signatures.
  • Implements Triple Diffie-Hellman key exchange protocol.
  • Leverages AES-256 keys in Galois/Counter Mode for encryption.
  • Generates new encryption keys frequently.
  • Stores private encryption keys only on each user’s device.

This ensures messages can only be read by the sender and recipient, not even WhatsApp servers. WhatsApp cannot decrypt them due to lack of access to encryption keys.

Integration With Mobile Operating Systems

WhatsApp integrates deeply into mobile operating systems to enable seamless messaging:

  • Android – Uses features like notification listener service and accessibility service to detect messages and sync in background.
  • iOS – Leverages push notifications, VoIP services, CallKit framework and native contact integration.

This OS-level integration provides user benefits like displaying messages on lock screen and seamless call transition between WhatsApp and native phone app.

The Future

WhatsApp continues to innovate and evolve its messaging system for the future:

  • Developing new voice and video calling infrastructure to improve quality.
  • Expanding support for group sizes beyond 256 participants.
  • Building integrated business messaging and commerce features.
  • Implementing Stories and Status features comparable to Instagram and Snapchat.
  • Rolling out opt-in end-to-end encryption for backed-up messages.

While the core XMPP-based messaging paradigm will remain, WhatsApp plans to expand the platform into an increasingly versatile communications and business service.

Conclusion

WhatsApp relies on the trusted XMPP protocol to provide a fast, reliable, scalable and secure messaging service to billions globally. Its custom optimizations for routing, media transfer, encryption and OS integrations enable seamless messaging and call connectivity across devices and networks. While largely transparent to users, this robust underlying messaging system powered by Erlang will continue evolving to support WhatsApp’s growth for years to come.