Design a One-to-One Chat System
Design a real-time one-to-one chat system with the following capabilities:
Core Requirements
- User Authentication: Registered users must authenticate before establishing a connection.
- Persistent Connections: Clients maintain a persistent connection, such as a WebSocket, to receive messages in real time.
- Text Messaging: Support sending text messages between any two authenticated users.
- Message Persistence & Offline Delivery: Chat history must be persisted, and messages should be delivered to users who were offline when the message was sent, upon their next login.
- Reliability & Ordering: Minimize message loss and duplicates, and preserve per-conversation message ordering as much as practical.
- Scalability: The system must be designed to scale horizontally.
Deliverables
Describe the backend architecture, key services involved, the data model, and the end-to-end message flow. Additionally, explain the following specific aspects:
- How authentication and session establishment work.
- How client connections are routed to the correct backend server.
- How online presence is tracked for users.
- Where a message broker (e.g., Kafka) would or would not fit into this architecture.
- The typical consumer latency expected from Kafka in a production setup.
- How Kafka differs from Redis Pub/Sub or Redis Streams for this specific use case.
AI interview prep
Core dilemma
Balancing the low-latency, real-time delivery requirements of a chat system with the strict demands for message persistence, guaranteed delivery (including offline), ordering, and horizontal scalability, while managing stateful connections.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Design a One-to-One Chat System
Design a real-time one-to-one chat system with the following capabilities:
Core Requirements
- User Authentication: Registered users must authenticate before establishing a connection.
- Persistent Connections: Clients maintain a persistent connection, such as a WebSocket, to receive messages in real time.
- Text Messaging: Support sending text messages between any two authenticated users.
- Message Persistence & Offline Delivery: Chat history must be persisted, and messages should be delivered to users who were offline when the message was sent, upon their next login.
- Reliability & Ordering: Minimize message loss and duplicates, and preserve per-conversation message ordering as much as practical.
- Scalability: The system must be designed to scale horizontally.
Deliverables
Describe the backend architecture, key services involved, the data model, and the end-to-end message flow. Additionally, explain the following specific aspects:
- How authentication and session establishment work.
- How client connections are routed to the correct backend server.
- How online presence is tracked for users.
- Where a message broker (e.g., Kafka) would or would not fit into this architecture.
- The typical consumer latency expected from Kafka in a production setup.
- How Kafka differs from Redis Pub/Sub or Redis Streams for this specific use case.