KatInterview

Architect a Multi-Tenant Team Chat Service with Live Delivery

System DesignModel answer
MediumModel answerSystem Designsystem-designreal-timewebsockets

Last updated

Design a multi-tenant team chat product covering channels, DMs, real-time delivery, history sync, search, and notifications, with per-channel ordering and tenant isolation.

Problem

Design the backend for a team chat product in which organizations (workspaces) have their own members and conversations.

Functional requirements

  • Workspaces act as tenants. Each has users and channels, which may be public or private.
  • Direct conversations: one-to-one and small group chats.
  • Messages are delivered in real time to web and mobile clients.
  • Message history is persisted and stays in sync across a user's devices.
  • Users can search messages within their own workspace.
  • Notifications fire for mentions, direct messages, and (optionally) channel activity.

Non-functional requirements

  • High availability and low delivery latency.
  • Scales to a very large number of workspaces, and to individual channels with tens of thousands of members.
  • Messages within one channel keep a consistent order.
  • Strong security and data isolation between workspaces.

What to cover

  1. High-level architecture
  2. Key APIs and the data model
  3. The real-time delivery mechanism
  4. Storage and sharding strategy
  5. How search and notifications work
  6. Major trade-offs and bottlenecks

State your own scale assumptions up front and use them to justify your choices.

Hints

Hint 1

Decide early whether a message is stored once per channel or once per recipient, and see how that choice affects write cost for a 50K-member channel.

Hint 2

Ordering only has to hold inside a channel. Think about what single component can hand out a monotonically increasing sequence number per channel, and how clients can detect and repair gaps.

Hint 3

For fanout, avoid looping over members. Consider having each connection server subscribe to channels, so a message is published once per channel and cost scales with servers, not members.

Hint 4

Use different stores for different needs: relational metadata sharded by tenant, a wide-column store for message history partitioned by channel, and a separate search index fed asynchronously from an event log.