Katkat

Design a one-to-one chat system

AnthropicSoftware Engineer · Technical Screen

Last 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

  1. Users can send and receive messages in real-time.
  2. Users can see their own message status (e.g., Sent, Delivered, Read).
  3. Users can see the online status (Presence) of their contacts.

Non-Functional Requirements

  1. Low latency: Messages should be delivered in milliseconds.
  2. Reliability: Messages must not be lost and should be delivered in the order they were sent.
  3. 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?