KatInterview

Design a real-time group messaging platform

System DesignModel answer
HardModel answerSystem Designreal-time-messagingwebsocketsscalability

Last updated

Design a scalable chat platform with channels and DMs supporting millions of users, sub-200ms delivery, message ordering, presence, and cross-device history sync.

Problem Statement

Design a collaborative messaging platform that supports team-based communication through organized channels and direct messages. The system must handle millions of daily active users with fast message delivery, persistent conversation history accessible from any device, and real-time presence indicators showing who is online.

Functional Requirements

  1. Users can send and receive messages instantly within shared channels or through private direct messages.
  2. Conversation history must persist and remain consistent when a user switches between devices.
  3. Users can see which of their colleagues are currently online or away.

Non-Functional Requirements

  1. The platform must be highly available with message delivery latency under 200 milliseconds.
  2. Messages within a single conversation must arrive in a deterministic, ordered sequence.
  3. The system must scale to handle thousands of messages per second at peak load.

What You Should Cover

  • API and Protocol Design: Define the REST endpoints and the real-time WebSocket event formats for sending, receiving, acknowledging, and syncing messages.
  • Data Model: Propose a storage schema that supports fast appends for new messages and efficient retrieval of recent history. Discuss your choice of database technology.
  • Architecture: Walk through how a message travels from sender to all recipients, including how you handle delivery to users in large channels with many online members.
  • Trade-offs: Explain where you chose consistency over availability and vice versa, particularly around message persistence and presence updates.
  • Resilience: Describe how the system handles dropped connections, client reconnections, and network partitions without losing or duplicating messages.

Hints

Hint 1

Think about what makes writes expensive: is it storing the message or delivering it to many recipients? Separate those concerns.

Hint 2

A per-channel monotonic sequence number solves both ordering and gap detection on reconnect. Who assigns it and how do you keep that assignment scalable?

Hint 3

Presence changes constantly and does not need to be perfectly accurate. What data structure and staleness tolerance lets you avoid flooding the system with presence updates?

Hint 4

Storing one copy of a message per recipient kills large channels. What if online users get a lightweight push notification and offline users simply fetch on demand?