System Design LabSystem Design QuestionsDesign Slack

Design Slack

MediumMessaging Systemsmessagingreal-timewebsocketssearchnotifications

Question Overview

Design a real-time team chat platform with workspaces, channels, direct messages, and threads. The core problems are holding millions of WebSocket connections, fanning messages out to channel members in a consistent order, and tracking unread counts and presence at scale.…

Sign up to see the full question and AI interviewer

Requirements

  • Workspaces with public and private channels, DMs, group DMs, and threaded replies
  • Send, edit, and delete messages with mentions and reactions, delivered in real time to online members
  • Channel history with infinite scroll, plus per-channel unread counts and mention badges synced across devices
  • Presence and typing indicators, and push notifications for offline and mobile users
  • Search across every channel a user can access, with new messages indexed within seconds
  • Under 500 ms p99 delivery, durable acknowledged messages, and one consistent order per channel

Back-of-the-envelope numbers

  • Messages: 1B/day ÷ 86,400 s ≈ 11.6K messages/s average, ~35K/s at 3× peak during working hours
  • Fan-out: 11.6K/s × 20 online members ≈ 232K deliveries/s average, ~700K/s at peak; one post to a 100K-member channel is 100K pushes alone
  • Connections: 10M concurrent WebSockets ÷ 50K per gateway server = 200 servers, ~300 with headroom for failover
  • Storage: 1B × 500 B = 500 GB/day ≈ 183 TB/year of message data, ~550 TB/year with 3× replication
  • Presence: 10M online users heartbeating every 30 s ≈ 333K updates/s, so presence lives in memory, not in the message store
  • Unread pointers: 20M users × ~50 channels = 1B last-read entries × ~24 B ≈ 24 GB in a sharded key-value store

Key components

  • Gateway servers: hold WebSocket connections, authenticate on connect, and track which channels each connection subscribes to
  • Message service: checks membership, assigns a per-channel sequence number, and persists the message before acknowledging the sender
  • Message store: wide-column or sharded SQL, partitioned by channel_id and time bucket and clustered by sequence for fast history range reads
  • Channel fan-out: a router maps each channel to the gateways holding its subscribers, so a 100K-member post fans out to hundreds of gateways, not 100K users
  • Unread tracking: per user per channel last_read_seq; the unread count is latest_seq minus last_read_seq, with mentions counted separately
  • Presence service: in-memory heartbeats with TTLs, publishing changes only to clients currently displaying that user
  • Search and notifications: messages stream through Kafka to a per-workspace search index with ACL filtering, and to APNs or FCM for offline users

Common mistakes

  • Ordering messages by each server's receive timestamp, so clock skew shows members different orders instead of one per-channel sequence
  • Writing every channel message into each member's inbox, turning one post in a 100K-member channel into 100K writes
  • Computing unread counts with COUNT(*) over messages on every load instead of subtracting sequence numbers
  • Broadcasting every presence change to every member of a 200K-member workspace, which grows quadratically with workspace size
  • Acknowledging the sender before the message is durably stored, so a crash loses messages users believe were sent
  • Assuming WebSockets never drop; without resuming from the last seen sequence, reconnecting clients silently miss messages

Likely follow-ups

  • How would a client that was offline for three days efficiently catch up across 200 channels?
  • How would you support a channel shared between two different companies' workspaces?
  • How would you propagate edits and deletes so search results and every client stay consistent?
  • How would you deploy a new gateway version without dropping 10M connections at once?
  • How would you enforce per-workspace retention policies and legal holds?
  • How would you keep unread state consistent across a user's desktop and mobile clients?

No community solutions yet

Be the first to publish your solution

Practice ‘Design Slack’ with an AI Interviewer

Get scored feedback on your diagram, scalability approach, and trade-offs. Free while we grow — up to 3 full interviews a day.