KatInterview

Design a Multi-Tenant Real-Time Chat Platform at Global Scale

System DesignModel answer
HardModel answerSystem Designwebsocketsmulti-tenancyfan-out

Last updated

Design a collaborative messaging system supporting thousands of isolated organizations, millions of concurrent users, real-time delivery under 200ms, and global traffic distribution.

Scenario

A company is building a team collaboration platform similar to workplace messaging tools. It needs to support 10,000 organizations ("tenants"), ranging from two-person startups to enterprises with 50,000+ employees, all sharing the same underlying infrastructure while remaining fully isolated from one another.

You are asked to design this system from scratch for a system design interview. Walk through your reasoning at each step.

Functional Requirements

  • Users can send and receive messages in group channels or one-on-one conversations.
  • Message history is persisted and pageable.
  • Users can see whether others are online, away, or offline.
  • Messages must be delivered in order within a channel.

Non-Functional Requirements

  • End-to-end message delivery latency under 200 ms (sender to recipient, within a region).
  • Strong data isolation between tenants — one organization must never access another's data.
  • High availability globally, with regional presence to serve traffic during local business hours.
  • The platform must not degrade for small tenants when a large tenant experiences a traffic spike.

What You Are Expected to Cover

  1. API Design — Core endpoints for sending messages, retrieving history, managing presence, and the WebSocket contract.
  2. Data Model — Schema for messages, channels, and memberships that handles multi-tenancy and supports efficient history queries.
  3. Architecture — End-to-end message delivery flow, including real-time push, persistence, and offline notifications.
  4. Scalability — How you prevent a single large tenant from degrading the experience for everyone else ("noisy neighbor" problem).

Scale Assumptions to Work From

  • 10M daily active users; roughly 5M concurrent WebSocket connections at peak.
  • Average of 50 messages per user per day (~6,000 messages/sec average, ~30,000/sec peak).
  • An average channel message is seen by ~20 online users, making fan-out the dominant bottleneck.
  • Messages average ~1 KB; about 500 GB of new message data per day.
  • SLA: 99.99% availability; under 200 ms delivery within a region.

Hints

Hint 1

Start by separating the write path (sender → durable log) from the fan-out path (log → recipients' sockets). They have very different scaling characteristics and should not block each other.

Hint 2

Multi-tenancy is not just a schema choice — think about it in layers: routing, storage placement, rate limiting, and resource bulkheads. A single 'shared table with tenant_id' answer misses most of it.

Hint 3

Presence and typing indicators are eventually consistent by nature. Identify early which signals can be shed under load without breaking core messaging guarantees.