What is Web WhatsApp?

Requirements of WhatsApp’s Design

Details
The design of WhatsApp involves integrating various components and building blocks to meet its functional requirements efficiently. Here’s a concise overview:
- Data Stores: WhatsApp utilizes different data storage solutions for various types of data. User and group information is stored in relational databases like SQL. For messages, WhatsApp uses the Mnesia database cluster due to its capability to store messages for a short duration efficiently. Media files such as images and videos are stored in blob storage to handle large data volumes.
- Distributed Cache: The WebSocket protocol connects each active device to a WebSocket server, which assigns a port to each online user. The Redis cluster acts as a distributed cache, storing mappings between WebSocket servers, ports, and users, and caching data from MySQL databases to enhance performance.
- CDN (Content Delivery Network): To efficiently serve high-demand content to users, WhatsApp employs CDNs. This approach ensures quick and reliable access to frequently requested media files.
- Messaging Queue: Services within WhatsApp are decoupled using messaging queues or Kafka. This setup facilitates group messaging by connecting the message service with the group message service. The message service interfaces with the Mnesia database cluster for message storage and retrieval, while the group message service manages group-related information atop the MySQL database cluster.
- The workflow for meeting WhatsApp’s functional requirements includes establishing communication channels between clients and servers through WebSocket servers and managing these connections with a WebSocket manager on a Redis cluster. Messages are processed and stored in a Mnesia database cluster, with end-to-end encryption ensuring secure communication. Media files are managed by an asset service, which stores them in blob storage for efficient retrieval.
This design addresses key functional requirements such as one-on-one and group conversations, message delivery acknowledgments, media file sharing, persistent storage of chat messages for offline users, and notifications for offline users upon becoming online.
Understanding these components and their workflow is crucial for designing a scalable and secure communication platform like WhatsApp.
High-level Design of WhatsApp

Details
To scale the high-level design of WhatsApp to support billions of users, it’s crucial to implement a highly scalable and distributed system. This can be achieved by utilizing multiple WebSocket servers for handling connections, employing a WebSocket manager with a Redis cluster for user mapping and server assignments, leveraging a message service with a Mnesia database cluster for storing and retrieving messages, and managing user and group data through a group service on a MySQL database cluster with Redis caching. These strategies distribute the workload across various servers and databases, and use replication and caching to manage the vast amount of data efficiently.
Detailed Design of WhatsApp

Why is WebSocket preferred over HTTP(S) protocol for client-server communication?


The data in the cache will become outdated if a user gets disconnected and connects with another server. Keeping this in mind, how long should a WebSocket server cache information?


Evaluation of WhatsApp’s Design

In the event of a network partition, what should the system choose to compromise between consistency and availability?


