📚 Main Topics
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)
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
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.
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
Group Messaging Logic
- Uses Kafka for message queuing and handling.
- Group message handler retrieves user connections and sends messages accordingly.
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.