Chat application with video messaging
Problem Statement
Design a real-time chat application that allows users to send text messages, media files (images, videos, documents), and short video messages (like WhatsApp, Telegram, or Instagram DMs).
The system should ensure low-latency message delivery, reliable video upload and playback, end-to-end encryption, and high availability across millions of concurrent users.
🎯 Objective
Build a scalable, secure, and performant messaging platform that supports:
✅ Functional Requirements
1. User & Authentication
2. Chat Functionality
3. Video Messaging
4. Real-Time Messaging
5. Media Storage & Retrieval
6. Notifications
7. Security & Privacy
8. Message Sync & Backup
⚙️ Non-Functional Requirements
| Attribute | Goal |
| ---------------- | -------------------------------------------- |
| **Scalability** | Millions of concurrent users and chats |
| **Latency** | Message delivery < 100 ms; video upload < 2s |
| **Availability** | 99.99% uptime |
| **Consistency** | Eventual consistency across devices |
| **Durability** | No message loss even if servers crash |
| **Security** | E2E encryption + OAuth2 authentication |
| **Storage** | Efficient video compression + CDN caching |
🧩 Core Components
| Component | Responsibility |
| ------------------------- | ---------------------------------------------------------- |
| **User Service** | Manages authentication, sessions, and profiles. |
| **Chat Service** | Handles chat room creation, messaging logic, and metadata. |
| **Message Queue Service** | Manages message persistence and ordering. |
| **Media Service** | Uploads, stores, and serves videos/images. |
| **Notification Service** | Pushes alerts for messages and video events. |
| **Presence Service** | Tracks online/offline/typing status. |
| **Sync Service** | Syncs messages across multiple devices. |
| **Encryption Service** | Manages key exchange and E2E encryption. |
🧱 High-Level Architecture
1
2 +----------------------------+
3 | Client Layer |
4 | (Web, Android, iOS Apps) |
5 +-------------+--------------+
6 |
7 v
8 +------------+------------+
9 | API Gateway |
10 +------------+------------+
11 |
12 +-------------------------------------------------------+
13 | Backend |
14 |-------------------------------------------------------|
15 | Auth Service Chat Service Media Service |
16 | Presence Service Message Broker Notification Svc |
17 |-------------------------------------------------------|
18 | Kafka / Redis Streams / RabbitMQ |
19 +-------------------------------------------------------+
20 |
21 v
22 +-------------------+ +-----------------------+
23 | Object Storage | | Database Layer |
24 | (S3 / GCS / CDN) | | (Cassandra / MongoDB) |
25 +-------------------+ +-----------------------+🧾 Data Model (Simplified)
User Table
| Field | Description |
| ----------- | ---------------------- |
| user_id | Unique user identifier |
| name | Display name |
| phone/email | Contact info |
| status | Online/Offline |
| last_seen | Timestamp |
Chat Table
| Field | Description |
| --------------- | ------------- |
| chat_id | Unique ID |
| chat_type | 1:1 or group |
| participant_ids | List of users |
| created_at | Timestamp |
Message Table
| Field | Description |
| ------------ | ----------------------- |
| message_id | Unique ID |
| chat_id | Associated chat |
| sender_id | Sender |
| content | Text or media reference |
| message_type | TEXT / VIDEO / IMAGE |
| timestamp | Creation time |
| status | Sent / Delivered / Read |
⚡ Scalability Considerations
| Challenge | Solution |
| ------------------------ | ----------------------------------------------- |
| **High concurrency** | Shard chat storage by user_id or chat_id. |
| **Message ordering** | Use Kafka or Redis streams per chat. |
| **Video upload latency** | Use presigned URLs + async background encoding. |
| **CDN optimization** | Use regional edge caching for fast video loads. |
| **Multi-device sync** | Use timestamp/version-based reconciliation. |
🔐 Security
📊 Observability & Metrics
⚙️ Tech Stack (Example)
| Layer | Technology |
| ---------------------- | ------------------------------------- |
| **Frontend** | React Native / Flutter |
| **Backend** | Go / Node.js / Java Spring Boot |
| **Database** | Cassandra / DynamoDB (for messages) |
| **Cache** | Redis |
| **Queue** | Kafka / RabbitMQ |
| **Media Storage** | AWS S3 + CloudFront CDN |
| **WebSocket Gateway** | NGINX + Socket.IO / gRPC |
| **Encryption** | libsodium / Signal Protocol |
| **Push Notifications** | Firebase Cloud Messaging (FCM) / APNs |
🧩 Key APIs
| API | Method | Description |
| ------------------------- | ------ | ----------------------------- |
| `/api/auth/register` | POST | Register new user |
| `/api/chat/create` | POST | Create new chat |
| `/api/message/send` | POST | Send message or video |
| `/api/media/upload-url` | GET | Generate presigned upload URL |
| `/api/message/history` | GET | Fetch chat history |
| `/api/notifications/push` | POST | Send notification to users |
💡 Possible Extensions
✅ End Goal
Design a scalable, secure, and real-time chat system that supports text and video messaging, ensures low latency communication, encrypted media handling, and seamless user experience across devices and geographies.