Detailed Design of WhatsApp
Learn about the design of the WhatsApp system in detail, and understand the interaction of various microservices.
Detailed design
The high-level design discussed in the previous lesson doesn’t answer the following questions:
-
How is a communication channel created between clients and servers?
-
How can the high-level design be scaled to support billions of users?
-
How is the user’s data stored?
-
How is the receiver identified to whom the message is delivered?
To answer all these questions, let’s dive deep into the high-level design and explore each component in detail. Let’s start with how users make connections with the chat servers.
Connection with a WebSocket server
In WhatsApp, each active device is connected with a WebSocket server via WebSocket protocol. A WebSocket server keeps the connection open with all the active (online) users. Since one server isn’t enough to handle billions of devices, there should be enough servers to handle billions of users. The responsibility of each of these servers is to provide a port to every online user. The mapping between servers, ports, and users is stored in the WebSocket manager that resides on top of a cluster of the data store. In this case, that’s Redis.
Point to Ponder
Why is WebSocket preferred over HTTP(S) protocol for client-server communication?
Send or receive messages
The WebSocket manager is responsible for maintaining a mapping between an active user and a port assigned to the user. Whenever a user is connected to another WebSocket server, this information ...
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.