Skip to main content

WhatsApp

What is Web WhatsApp?​

img_703.png img_704.png

Requirements of WhatsApp’s Design​

img_705.png img_706.png img_707.png img_708.png img_709.png img_710.png img_711.png img_712.png

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​

img_713.png img_714.png img_715.png img_716.png img_717.png img_718.png img_719.png img_720.png img_721.png img_722.png img_723.png img_724.png

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​

img_725.png


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

img_727.png img_728.png


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? img_729.png

img_730.png img_731.png img_732.png img_733.png img_734.png img_735.png img_736.png

Evaluation of WhatsApp’s Design​

img_737.png


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

img_738.png

img_739.png img_740.png

img_741.png img_742.png img_743.png img_744.png img_745.png