KatInterview

Build a Team Chat Platform with Live Delivery and Sync

System DesignModel answer
HardModel answerSystem Designsystem-designwebsocketsmessaging

Last updated

Design a workplace chat backend covering DMs and channels, with sub-second delivery, durable acknowledged messages, per-conversation ordering, and consistent history across devices.

Design a Workplace Chat Backend

You are asked to design the backend for a team chat product. People talk one-on-one in direct messages and in shared channels. The service must serve millions of users online at once, and a message sent to an online recipient should appear almost immediately.

What the product must do

  • A user can post a message to another person or to a channel.
  • A user can read earlier messages and see the same history on every device they own.
  • A user who is online receives new messages live, without refreshing.

Quality bars

  • Durability: once the system confirms a message to the sender, it must never be lost.
  • Scale: it must stay healthy at the busiest hours of the day.
  • Ordering: inside one conversation, messages appear in the same chronological order for everyone.
  • Latency: online recipients see new messages nearly instantly.

What to cover in your answer

  1. Interfaces: the main calls for sending, fetching history, and keeping a live connection open.
  2. Storage: a schema (SQL, NoSQL, or a mix) for users, channels, memberships, and messages.
  3. Architecture: how messages are pushed live, and how every active device of a given user gets them.
  4. Scaling: how you split message data for very large channels and how you cope with a few extremely busy ("hot") conversations.

State your own usage assumptions and do a quick capacity estimate before drawing the design.

Hints

Hint 1

Begin with numbers: messages per second at peak, concurrent sockets, and the size of the largest channels. You will likely find that fan-out deliveries, not writes, dominate the load.

Hint 2

Ordering across the whole system is unnecessary. Give each conversation a single writer that hands out an increasing sequence number, and let clients use it to detect duplicates and gaps.

Hint 3

Separate the acknowledgement from the delivery. Acknowledge the sender only after a durable append, then let independent consumers handle persistence and live push. Make retries safe with a client-generated message id.

Hint 4

To avoid per-member fan-out, have each gateway subscribe to the channels its connected users belong to, so a message is published once per channel and reaches only gateways that have listeners.