Design a one-to-one chat system
AnthropicSoftware Engineer · Technical ScreenLast updated
This problem tests your ability to design a scalable, real-time one-to-one messaging system by addressing requirements for message ordering, delivery guarantees, and user presence.
Problem Statement
Design a backend architecture for a real-time, one-to-one chat application (similar to WhatsApp or Messenger). The system must support millions of concurrent users.
Functional Requirements
- Users can send and receive messages in real-time.
- Users can see their own message status (e.g., Sent, Delivered, Read).
- Users can see the online status (Presence) of their contacts.
Non-Functional Requirements
- Low latency: Messages should be delivered in milliseconds.
- Reliability: Messages must not be lost and should be delivered in the order they were sent.
- Scalability: The system must handle high traffic volume during peak hours.
Scope
Design the API, database schema, and high-level architecture. Explain how you would handle message ordering, delivery notifications, and the persistence layer for message history.
Hints
Hint 1
Consider the trade-offs between using WebSockets for full-duplex communication versus long-polling for simplicity.
Hint 2
For message ordering and reliability, think about how sequence numbers or timestamps can be utilized alongside a message queue or a distributed database.
Hint 3
To handle presence at scale, evaluate the difference between a centralized database store and a distributed cache like Redis with expiration policies.
Follow-up questions
- How would you modify your design to support group chats with thousands of participants?
- If a user is offline, how do you ensure they receive all missed messages upon reconnecting without overloading the server?
- How would you handle global consistency if users are geographically distributed across different continents?
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.