Design Omegle (Anonymous 1-on-1 Chat)
Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2025-06-24
Problem Statement
Design a system like Omegle that allows two random users to be matched and chat anonymously in real time. The system should support:
•Random user pairing
•Text chat
•Scalability to support millions of concurrent users
🎯 Functional Requirements:
1.Anonymous Random Chat
•Connect a user to a random stranger
•1-on-1 text chat session
2.Message Exchange
•Real-time message sending and receiving
•Typing indicators (optional)
3.Session Management
•Start and end a chat session
•Disconnect/reconnect handling
4.User Controls
•Skip current partner
•Report/flag user (optional)
•Add interest-based matching (optional)
5.Optional Features
•Interest-based matching (/topics)
•Video support (future scope)
⚙️ Non-Functional Requirements:
•Low latency chat (< 100ms)
•High availability and fault tolerance
•Horizontal scalability
•Handle millions of users concurrently
•Stateless or minimal-session architecture
•Ensure privacy and anonymity
•Moderate abuse/spam (optional, future)
🧱 Key HLD Components:
1.Client (Web/Android/iOS):
•UI for entering chat
•Connects via WebSocket or long polling
2.API Gateway / Load Balancer:
•Routes chat traffic
•Handles load distribution
3.Matchmaking Service:
•Maintains a queue of waiting users
•Randomly pairs two users
•Supports interest/topic-based matching
4.Chat Service:
•Manages real-time message delivery (WebSocket)
•Handles message queues for each chat session
•Ensures delivery ordering
5.Session Manager:
•Tracks ongoing chat sessions
•Handles disconnections and cleanup
6.User Service (Optional):
•Track IP/device (if needed for moderation)
•Anonymous user IDs/session tokens
7.Notification Service:
•Typing indicator
•Timeout alerts, skip notifications
8.Moderation Service (Optional):
•Abuse/spam detection
•Flag/report functionality
9.Database(s):
•In-memory store (Redis) for active user queue
•NoSQL store (e.g., DynamoDB/Cassandra) for chat logs (if persisted)
•Object store (S3) for chat/media logs (optional)
🗂️ Data Models (Simplified):
UserSession
1json
2CopyEdit
3{
4 "session_id": "uuid",
5 "status": "waiting | chatting | disconnected",
6 "partner_session_id": "uuid",
7 "interests": ["sports", "tech"]
8}Message
1json
2CopyEdit
3{
4 "message_id": "uuid",
5 "from_session_id": "uuid",
6 "to_session_id": "uuid",
7 "timestamp": 162894,
8 "content": "hello",
9 "type": "text | media"
10}🔄 Sequence (Chat Session Flow):
1.User opens Omegle → joinQueue()
2.Matchmaking Service → finds a pair
3.Starts session via Chat Service
4.Messages exchanged via WebSocket
5.Either user → endSession() or skip()
6.Cleanup session → return to matchmaking
📈 Scalability and Performance:
•Use WebSocket servers with horizontal scaling (via sticky sessions or Redis pub-sub)
•Use Redis queue for real-time matchmaking
•Stateless services for auto-scaling