KatInterview

Workspace Chat Platform with Per-Org Isolation

System DesignModel answer
MediumModel answerSystem Designmulti-tenancymessagingreal-time

Last updated

Design a chat backend for many isolated organizations, covering ordered channel history, offline catch-up, permission-aware search, presence, and read tracking.

Context

You are building the core backend for a workplace chat product. Many independent organizations (tenants) use it. Each organization has its own people, channels, and admins, and nothing one organization stores may ever be visible to another.

The product supports:

  • One-to-one direct messages and group conversations.
  • Three kinds of channels: public (anyone in the org can find and join), private (invite-only but discoverable to members), and invitation-only (hidden from non-members).
  • Administrator roles that control channel creation, membership, and moderation.
  • Durable message history that can be searched.
  • Real-time delivery to people who are online, and catch-up for people who were offline.
  • Online presence and per-user read positions.

A single person may belong to several organizations. Their identity is global, but their role and permissions are scoped to each organization they belong to.

Requirements

  • Messages are durable once the sender receives confirmation.
  • Within one conversation, every participant sees the same message order. There is no ordering requirement across different conversations.
  • Channels may have anywhere from a handful of members to many thousands.
  • Clients reconnect often and may resend a message if they never received an acknowledgment.
  • Search results and search indexes follow the same tenant and conversation permissions as direct reads.

What to cover

Explain your choices for:

  1. The core data model (tenant, user, membership, conversation, message, read position, idempotency key).
  2. How messages get their order and how duplicate sends are prevented.
  3. The write path and the real-time fan-out path, including reconnect and offline catch-up.
  4. Where and how permissions are enforced.
  5. Fan-out strategy for very large channels.
  6. Tenant isolation, from shared storage with enforced policies up to dedicated storage for large or regulated tenants.
  7. Search indexing that respects permissions, and how deletions and retention apply to it.
  8. Presence and read-receipt design, failure handling, and observability.

Before designing, state assumptions about peak message rate, tenant size distribution, retention, attachment limits, and whether edits, deletes, threads, or legal holds are in scope.

Hints

Hint 1

Separate the durable write from the real-time push. Assign the per-conversation sequence number at write time, and only fan out after the message is committed.

Hint 2

Make sends idempotent by giving each client-generated message a unique key scoped to the conversation. A retry with the same key should return the original message rather than creating a second one.

Hint 3

Permission checks belong on every path that returns data: writes, reads, push delivery, and search hits. Consider putting the tenant ID into every key and query, and treating the search index as a copy that inherits the same access rules.