WhatsApp System Design
High-Level Architecture
2 min read
A messaging platform is not a single application.
It consists of multiple specialized services working together.
Components
Client
The mobile or desktop application.
Responsible for:
- Sending messages
- Receiving events
- Local storage
- Encryption
- UI updates
WebSocket Gateway
Maintains millions of persistent client connections.
Instead of opening a new HTTP connection for every message, clients maintain one long-lived WebSocket connection.
This enables instant message delivery.
Messaging Service
Responsible for:
- Validating requests
- Creating Message IDs
- Storing encrypted payloads for durable delivery
- Publishing delivery events
Think of this as the brain of the messaging platform.
Message Queue
Instead of delivering every message synchronously, the messaging service publishes events to a queue.
Common technologies include:
- Kafka
- RabbitMQ
- Pulsar
This allows delivery to happen asynchronously without slowing down the sender.
Delivery Service
Responsible for locating recipients and pushing events to their connected devices.
If a recipient is offline, delivery can be retried later.
Presence Service
Tracks whether users are:
- Online
- Offline
- Typing
- Recently Active
This service powers the online indicator and typing indicator.
Pending Message Store
Holds encrypted messages safely until they can be delivered (and synced to the recipient's devices).
This is primarily store-and-forward, not a long-term plaintext chat history database. Once devices have received the message, server-side storage for that payload is no longer needed for chat history — the durable copy lives on clients.
Large messaging systems typically replicate this pending data across multiple servers for durability and availability while delivery is in progress.