Katkat

Design a team chat system

OpenAISoftware Engineer · Technical Screen

Last updated

This question tests the ability to design a scalable, low-latency, real-time messaging system, focusing on message ordering, delivery guarantees, and high-concurrency state management.

Problem Statement

Design a team-based chat system similar to Slack or Discord. Your design should support millions of daily active users, providing low-latency messaging, presence indicators, and channel-based organization.

Functional Requirements

  1. Users can send and receive messages in real-time within channels or direct messages.
  2. Users must be able to see their chat history across devices.
  3. Users should be able to see online/offline presence statuses for their teammates.

Non-Functional Requirements

  1. High availability and low latency (sub-200ms message delivery).
  2. Strong message ordering guarantees within a conversation.
  3. Scalability to support thousands of messages per second.

Expectations

  • API Design: Define the necessary endpoints and websocket/event protocols.
  • Data Model: Propose a database schema (SQL vs NoSQL) that handles message persistence and quick retrieval.
  • Architecture: Explain how messages are routed to recipients, including how you handle 'fan-out' for large channels.
  • Trade-offs: Discuss the balance between consistency and availability, specifically regarding message history and status updates.
  • Challenges: Address how you ensure message order and handle network partitions or client reconnections.

Hints

Hint 1

Consider using WebSockets for bidirectional communication to push updates to clients instead of polling.

Hint 2

Think about the data partitioning strategy: would you shard by user ID or by channel ID, and what are the implications for cross-device synchronization?

Hint 3

For 'fan-out' in large channels with thousands of members, evaluate the difference between a 'push' model (writing to all user mailboxes) and a 'pull' model (fetching on demand).

Follow-up questions

  • How would you modify your design to handle a viral channel where a single message might be sent to 50,000 active users simultaneously?
  • If you needed to implement a 'search' feature across past messages, what indices or external tools would you introduce?
  • How would you ensure exactly-once delivery of messages if the client or server crashes mid-transmission?