The summary of ‘Chat App | WhatsApp | Facebook Messenger | System Design’

This summary of the video was created by an AI. It might contain some inaccuracies.

00:00:0000:10:06

The video comprehensively discusses the design and implementation of a chat application similar to Facebook Messenger or WhatsApp, encompassing both functional and technical requirements. Key features include one-on-one and group chats, read receipts, multimedia sharing, and online status notifications. Technical needs highlight low latency, high availability, end-to-end encryption, and the use of WebSocket protocol for real-time communication.

Storage requirements are discussed, estimating around 75 petabytes for message history, and the video explains essential services like Messaging, Session, Relay, Last Seen, Asset, and Group Messaging services, each handling specific responsibilities. The database schema for the messaging system includes users, groups, unsent messages, and session tracking, utilizing both RDBMS and NoSQL databases for managing complex data relationships, especially for group messaging.

Furthermore, the process of sending images involves uploading to a server, obtaining an image ID, and storing this data in blob stores (e.g., AWS S3), ensuring encryption and compression for secure and efficient transfer. The speaker underscores the importance of clarity in design and adaptability to evolve with changing requirements.

00:00:00

In this segment of the video, the host outlines the key functional and technical requirements for designing a chat application similar to Facebook Messenger or WhatsApp. The functional requirements include features such as one-on-one and group chats, read receipts, online status sharing, notifications for new messages, and multimedia sharing. On the technical side, the system needs low latency, high reliability and availability, support for both mobile and desktop clients, storage for chat history, ability to handle large amounts of data, end-to-end encryption, and client-initiated connections using the websocket protocol instead of HTTP. The host also discusses concepts like websocket handlers and long polling in HTTP for maintaining open connections. Additionally, they touch on capacity planning, providing an example traffic estimation for 500 million active users sending 1.5 billion messages per day, which translates to around 18,000 messages per second.

00:03:00

In this segment of the video, the speaker discusses the storage requirements and API calls for a messaging application, explaining that storing all messages would require around 75 petabytes of data. Two primary API calls are identified: sending and receiving messages, which involve user IDs and text. The speaker then outlines the various services necessary to meet system requirements, including:

1. **Messaging Service**: Handles sending messages from one user to another via a bi-directional websocket connection, identifying recipients using the session service.
2. **Session Service**: Tracks which server a user is connected to, storing this data in a NoSQL database.
3. **Relay Service**: Temporarily stores messages for offline users in a database like Cassandra.
4. **Last Seen Service**: Logs user activity timestamps to show online status.
5. **Asset Service**: Manages multimedia files using storage solutions like AWS S3.
6. **Group Messaging Service**: Similar to messaging service but publishes messages to all group members, relying on the session service for user connections.

00:06:00

In this segment of the video, the discussion revolves around the database schema for a messaging service. It starts by mentioning the complexity of group messaging and the potential use of a hybrid database combining RDBMS and NoSQL. Key tables in the schema include users (user ID, username, contact number), groups (group ID, user ID for group members), unsent messages (message ID, sender and receiver IDs, content/media URL, timestamp), a last scene table (user ID, timestamp), and sessions (user ID, server ID).

The explanation then shifts to group messaging mechanics. Each group has a unique group ID linked to its users. When a user sends a group message, the WebSocket handler forwards it to a message service, which queues the message in a Kafka topic. The group message handler, as a Kafka consumer, retrieves the message, queries the group service for user IDs, then uses the WebSocket manager to identify their connected machines. Messages are sent via corresponding WebSocket handlers. If receivers are offline, messages are encrypted and stored until they come online. Media files are compressed, encrypted on the sender’s device, and decrypted on the receiver’s end.

00:09:00

In this part of the video, the process of sending images between users in an application is explained. When user A sends an image to user B, user A uploads the image to a server, obtains an image ID, and sends this ID to user B. User B then uses the ID to search for and download the image from the server. Alternatively, the image can be compressed on the device and sent to an asset service which determines the message type and stores it in a blob store, like an S3 bucket. Links to these media files are saved in a SQL or NoSQL database with user details mapping. The speaker emphasizes that there is no absolute right or wrong design, but clarity in meeting requirements and adaptability to changes are key.

Scroll to Top