KatInterview

Design a Real-Time Guild Chat Platform with Durable History

System DesignModel answer
EasyModel answerSystem Designreal-timewebsocketsmessage-ordering

Last updated

Design backend infrastructure for a Discord-like platform with servers, channels, DMs, real-time delivery, message persistence, and strict per-channel ordering at scale.

Design a Real-Time Guild Chat Platform

You are building the backend for a community communication platform organized around guilds (think: persistent groups), text channels within those guilds, and one-on-one direct messages. The platform must deliver messages in real time to connected clients while also guaranteeing that no message is lost, even when recipients are temporarily offline.

What the System Must Do

  1. Users can belong to many guilds and browse channels inside each one.
  2. Sending a message to a channel pushes it to every currently-online member of that channel with minimal delay.
  3. When a client connects or reconnects, it can pull any messages it missed during its absence.
  4. Messages in a given channel have a total, unambiguous order — no two members should ever see them in a different sequence.

Quality Bar

  • Message delivery latency stays low (sub-200 ms p99 within a region).
  • The platform stays highly available; partial component failures do not silence users.
  • The architecture scales to tens of millions of concurrent connections.

What to Cover in Your Answer

  • API surface: REST endpoints and WebSocket events the client uses.
  • Storage schema: How users, guilds, channels, memberships, and messages are persisted.
  • Delivery path: How a message travels from sender to database to online recipients, and how offline clients catch up.
  • Ordering guarantee: How strict per-channel ordering is maintained in a distributed setting where multiple servers handle writes.

Key Constraints

  • The user base is global and network conditions vary; assume frequent disconnects and reconnects on mobile.
  • Durability is non-negotiable: once the server acknowledges a message, it must survive any single-component failure.

Hints

Hint 1

Decouple message persistence from fan-out — ack only after a durable write, then publish asynchronously so a slow subscriber never blocks the write path.

Hint 2

Assign each channel to a single sequencer (Kafka partition or leased owner) so writes within that channel are totally ordered; clients render by sequence number, not arrival time.

Hint 3

Use an idempotency key (client nonce) so retries on flaky networks never create duplicate messages.

Hint 4

On reconnect, push recent missed messages for active channels but only send unread counts for stale ones — let the client lazy-load history on demand to avoid replay storms.