Chat App | WhatsApp | Facebook Messenger | System Design

by ByteMonk

📚 Main Topics

  1. Functional Requirements of a Chat Application

    • One-on-one chat
    • Group chat functionality
    • Read receipts (double tick marks)
    • Online status sharing
    • Notification system for new messages
    • Multimedia sharing (images, videos, files)
  2. Technical Requirements

    • Low latency for real-time communication
    • High reliability and availability
    • Support for both mobile and desktop clients
    • Storage for chat history
    • Handling large amounts of data (text, photos, videos)
    • End-to-end encryption
    • Client-initiated connections using WebSocket protocol
  3. System Design Components

    • Messaging ServiceHandles sending and receiving messages.
    • Relay ServiceTemporarily stores messages for offline users.
    • Session ServiceManages user connections and server mappings.
    • Last Seen ServiceTracks user activity timestamps.
    • Asset ServiceManages multimedia file storage and retrieval.
    • Group Messaging ServiceManages messages sent to groups.
  4. Database Schema

    • Users table: user ID, username, contact number
    • Groups table: group ID, user IDs of group members
    • Unsent messages table: message ID, sender ID, receiver ID, content/media URL, timestamp
    • Last seen table: user ID, timestamp
    • Sessions table: user ID, server ID mapping
  5. Group Messaging Logic

    • Uses Kafka for message queuing and handling.
    • Group message handler retrieves user connections and sends messages accordingly.
  6. Media File Handling

    • Media files are compressed and encrypted on the sender's device.
    • Files are uploaded to a server, and links are sent to the receiver for download.

✨ Key Takeaways

  • Real-time chat applications require careful consideration of both functional and technical requirements.
  • WebSocket protocol is preferred for real-time communication due to its persistent connection capabilities.
  • Proper capacity planning is essential, especially when dealing with large user bases and high message volumes.
  • A hybrid database approach may be necessary to accommodate different data types and relationships.

🧠 Lessons Learned

  • There is no one-size-fits-all design; flexibility and adaptability to requirements are crucial.
  • Understanding the underlying technologies (like WebSockets and Kafka) is important for implementing efficient systems.
  • Security measures, such as end-to-end encryption, are vital in protecting user data in chat applications.
  • Effective communication and clarification of requirements with stakeholders (like interviewers) can lead to better design outcomes.

🔒 Unlock Premium Features

This is a premium feature. Upgrade to unlock advanced features and tools.

🔒 Unlock Premium Features

Access to Chat is a premium feature. Upgrade now to unlock advanced AI-powered tools and enhance your experience!

🔒 Unlock Premium Features

Access to Mindmap is a premium feature. Upgrade now to unlock advanced AI-powered tools and enhance your experience!

🔒 Unlock Premium Features

Access to Translation is a premium feature. Upgrade now to unlock advanced AI-powered tools and enhance your experience!

Refer a Friend, Get Premium

Suggestions

🔒 Unlock Premium Features

Access to AI Suggestions is a premium feature. Upgrade now to unlock advanced AI-powered tools and enhance your experience!