Design a real-time chat system with hot groups
AirbnbSoftware Engineer · OnsiteLast updated
This problem tests your ability to design a distributed, low-latency messaging system that handles massive fan-out and identify trending group activities.
Design a Real-Time Chat System with 'Hot' Groups
Design a global real-time chat platform supporting 1:1 and group messaging. The system must support millions of concurrent users. A core requirement is to identify and cache 'hot' groups—groups with the highest message velocity—to optimize delivery performance.
Functional Requirements
- Send and receive messages in real-time.
- Support group chats with up to 10,000 members.
- Provide message history sync across multiple devices.
- Real-time delivery status (read receipts).
- Identify the Top 100 'hot' groups globally in near real-time.
Non-Functional Requirements
- Low latency: 99th percentile message delivery under 200ms.
- High availability and partition tolerance.
- Eventual consistency for message ordering.
Deliverables
- High-level architecture including API design and storage choices (SQL vs. NoSQL).
- Mechanism for real-time WebSocket connection management across a server cluster.
- A strategy for tracking and serving 'hot' groups without overloading the primary database.
- Handling message fan-out for large group chats.
Hints
Hint 1
Use a Pub/Sub mechanism combined with a distributed WebSocket gateway layer to route messages to users across different server nodes.
Hint 2
For 'hot' groups, consider using a sliding window counter approach with an in-memory data store like Redis to track message volume per group ID.
Hint 3
To handle large group fan-out, implement a broadcast strategy that separates the 'send' operation from the 'delivery' operation using a message queue.
Follow-up questions
- How would you handle the 'thundering herd' problem if a single group suddenly becomes viral and message volume spikes 100x?
- If users are in different geographic regions, how would you minimize latency for cross-region message delivery?
- How would you ensure exactly-once delivery of messages in the event of a network partition?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.