📱💻 A chat application like Facebook Messenger or WhatsApp should have one-on-one and group chat, read receipts, online status, and multimedia sharing for both mobile and desktop clients.
⚡🔒 Low latency and high reliability are crucial for a real-time chat application, along with end-to-end encryption and client-initiated connections.
📚🔍 The chat app needs to store chat history, handle large amounts of data including text, photos, and videos, and support notifications for new messages.
1️⃣ The video discusses the use of websocket protocol for a chat app, as it allows for an open connection between server and client.
2️⃣ Another option mentioned is long polling in HTTP, where the server keeps the client connection open until a timeout or threshold is reached.
3️⃣ In terms of capacity planning, it is estimated that the chat app will have around 18,000 messages per second and storage needs to handle billions of messages per day.
WhatsApp and Facebook Messenger handle billions of messages, requiring a storage capacity of 75 petabytes.
The two main API calls are sending messages and getting messages, with parameters such as user IDs, text, screen size, and timestamp.
The system design includes services such as messaging, relay, group, session, last scene, and asset.
💬 The messaging service uses a session service to identify and send messages to users.
📥 If a user is offline, the message is temporarily stored by the relay service until it can be delivered.
📅 The session service stores timestamps of user activity to track online status and differentiate between user and application activity.
🖼️ Asset services are used to store and retrieve multimedia files in a storage system like AWS S3.
👥 The group messaging service publishes messages to all users associated with the same group ID.
📌 The session service identifies the server to which each user is connected.
📚 The choice of database can be a relational database management system (RDBMS) or a hybrid database with NoSQL.
💬 Group chats have a separate database and each group has a unique group ID with user mappings.
💬 The chat app tracks active users and stores messages in a queue or Kafka topic.
📩 Group message handler sends messages to individual machines through websockets.
🔒 Media files sent over the chat are compressed, encrypted, and stored in the server's database.
📷 Images are uploaded to a server and assigned an ID, which can be used to search and download the image.
📱 Another method is to compress the image on the sending device and send it to the asset service.
🔒 The asset service stores media and image files in an S3 bucket, with links to the file locations stored in a database.