"Design Slack" sounds like "design WhatsApp with channels", and candidates who treat it that way lose points quickly. In a 1:1 chat a message has one recipient. In a workspace, a message in #general has tens of thousands of potential readers, most of whom are not looking at it right now.
The interviewer is testing whether you notice that the unit of design changes from the user's inbox to the channel. Do you model a channel as an ordered log that many people read, rather than copying each message to every member? Can you keep unread counts cheap? Can you avoid the quadratic trap in presence? And can you offer search that never shows someone a message from a channel they cannot see?
Direct-message delivery, offline queues and receipts are in Design WhatsApp. Here we spend our time on channels, fan-out inside a workspace, presence and search.
Clarify the requirements
Functional requirements:
- A workspace has public and private channels, plus direct messages and group DMs.
- Post a message in a channel and see it appear for everyone currently viewing it.
- Threads: replies attached to a parent message.
- Unread badges and mention counts for every channel in the sidebar.
- Presence: who is online or away.
- Search messages and files across the channels you can access.
Out of scope, said aloud: voice huddles, third-party app platform, workflow builder, enterprise compliance exports.
Non-functional requirements: these decide the architecture.
- Messages appear in under a second for people viewing the channel.
- Order within a channel is the same for everyone. Two people reading the same channel must see the same sequence.
- Permissions are enforced everywhere, including search, notifications and unread counts. A private channel's content must never leak through a side door.
- History is durable and searchable for years. Unlike a consumer chat, a workspace's history is the product.
- Workspaces are very uneven. Most have a dozen people. A few have hundreds of thousands, and the design must serve both.
Estimate the scale
Assume 20 million daily active users across all workspaces. Each posts 30 messages a day, and each loads or scrolls through about 500 messages a day (channel history, threads, notifications).
Writes: 20M × 30 = 600 million messages a day. 600M ÷ 86,400 ≈ 7,000 per second on average, and about 21,000 per second at peak (3x).
Reads: 20M × 500 = 10 billion message reads a day, or about 116,000 per second. That is a 17:1 read-to-write ratio.
Storage: at about 1 KB per message with metadata and attachment references, 600M × 1 KB = 600 GB a day, about 220 TB a year, and roughly 1.1 PB over a five-year retention. The search index adds a further fraction of that.
"7,000 writes a second is modest, and 1.1 PB is large but ordinary. The scale is not in the totals. It is in the skew: one message in one huge channel fans out to thousands, and a status change in a huge workspace can reach every client. The design has to be cheap for a ten-person team and survivable for a 500,000-person one."
You can reproduce the totals in the capacity estimator.
API and data model
Clients use HTTPS for history and actions and one WebSocket for everything live.
GET /v1/channels/{id}/messages?before=<ts>&limit=50
POST /v1/channels/{id}/messages { clientMsgId, text, threadTs? }
POST /v1/channels/{id}/read { upToTs }
GET /v1/search?q=...&in=...&from=...
WS subscribe { channelIds[] } -> events: message, edit, typing, presenceThe data is organized by channel, with reading state kept per person:
messages (channel_id PK, ts CK, user_id, text, thread_ts, edited_at)
channels (workspace_id PK, channel_id CK, name, is_private)
members (channel_id PK, user_id CK, role)
read_state (user_id PK, channel_id CK, last_read_ts, mention_count)The non-obvious choice: ts is a per-channel, strictly increasing timestamp, and it doubles as the message ID within the channel. It orders the channel, lets the client page with before=ts, and gives read_state a single number to compare against. Nothing is copied per member.
High-level design
We simulate the message path: clients on a WebSocket gateway, a messaging API that persists each post to a channel log and updates a search index, and a presence store.
- The gateway keeps one connection per client and passes posts to the messaging API.
- The API appends to the channel log, feeds the search index and reads or writes presence.
Describe this diagram
Components
- clients (Client)
- ws gateway (WebSocket gateway)
- messaging api (Service)
- channel log (Cassandra)
- search index (Search cluster (Elasticsearch))
- presence (Redis)
Connections
- clients sends to ws gateway
- ws gateway sends to messaging api
- messaging api sends to channel log
- messaging api sends to search index
- messaging api sends to presence
Run it, then try raising the load or cutting the search cluster to one node. Search indexing competes with history for the API's attention.
The write path: the API validates membership, assigns the next ts for the channel, appends the message to the log and acknowledges. It then publishes a message event to the channel's subscribers and queues the message for indexing.
The read path: opening a channel fetches the latest 50 messages by channel_id and ts, one partition read. Scrolling back pages on ts. The sidebar needs only read_state and each channel's latest ts, never the messages themselves.
The interesting problem: fan-out inside a channel
A channel is a shared log that many people read. The question is how a new message gets from the log to everyone who should see it. This is the same family of problem as the follower feed in Design Twitter, with one big difference: the audience is bounded and mostly passive.
Approach A: copy the message to every member's inbox
Write one row per member, as you would for a group DM.
Good: each user's view is a single partition read, and unread state is trivial.
Bad: a post in a 100,000-member #announcements channel is 100,000 writes, and almost all of them go to people who will never open it today. Edits and deletes must find and change every copy. Storage multiplies by channel size.
Approach B: one channel log, readers subscribe
Store the message once, in the channel's partition. Connected clients subscribe to the channels they care about, and the gateway pushes events to subscribers only.
Good: one write per message, and edits touch one row. Fan-out is paid in live pushes, bounded by who is actually online and looking.
Bad: unread state cannot be a property of the message, so it needs its own design, and a subscription map (which gateway cares about which channel) has to be maintained.
Approach C: log plus per-user cursors, with tiered delivery
Keep Approach B, and make delivery tiered by attention:
- Channels the user has open get full message events.
- Other channels in the sidebar get only a light badge event:
{channel, latestTs, mentionDelta}. - Channels never opened this session get nothing live. The badge is computed at connect time.
Unread count is derived, not stored per message: read_state.last_read_ts against the channel's latest ts, with a small counter for mentions.
This is the answer to aim for. You pay per attentive reader, not per member. A 100,000-member channel with 3,000 people watching is 3,000 pushes and one write.
Presence and search
Two features are famous for breaking naive designs.
Presence without the quadratic trap
If every client is told every status change in the workspace, then N users produce N changes each reaching N clients: N² messages. With 100,000 people in a workspace and 5 changes a person per hour, that is about 500,000 status changes an hour, each pushed to 100,000 clients, or 50 billion pushes an hour.
Fix it in three steps. Subscribe on demand: the client asks for presence only for the people on screen (the visible channel, the DM list), a few dozen at a time. Use heartbeats with a TTL: a Redis key per user that expires after about 30 to 60 seconds, so a dropped connection turns "away" without any event. Coalesce: flapping between states within a few seconds is not sent.
Search that respects permissions
Index messages asynchronously: the API publishes each post to a queue (see message queues), and an indexer writes it into a search cluster partitioned by workspace. Search freshness of a second or two is acceptable.
The hard part is who may see what. Indexing the channel ID with each document and filtering at query time by "channels this user belongs to" is simple and correct, but a user in 5,000 channels produces a huge filter. The usual compromise is to index each document with its channel and a visibility class, resolve the user's channel set at query time with a cache, and re-check each result against current membership before returning it. Removing someone from a private channel is then effective at once, even if the index has not caught up. See search systems for the index itself.
Bottlenecks and failures
A giant workspace. Partition data and gateway subscriptions by workspace, and treat the biggest workspaces as their own shards so that one cannot slow the rest. The long tail of tiny workspaces share infrastructure cheaply.
A hot channel. #general at the start of a company all-hands receives a burst of posts and reactions, all in one partition. Reactions and typing indicators should be batched and sampled rather than written individually, and the channel's ts assignment is the one serialized step, so keep it to one in-memory increment per channel owner.
Ordering within a channel. Route every write for a channel to one owner node (by hashing the channel ID), which assigns ts in sequence. If that node fails, another takes over from the last persisted ts. This is partitioning by the entity whose order you need.
What if the search index is behind or down? Posting and reading keep working because indexing is asynchronous and off the write path. Search results are stale until the indexer catches up, and the queue's depth is the number to alert on.
Trade-offs to name aloud
- One log per channel over per-member copies: cheap writes and edits, in exchange for deriving unread state.
- Presence by demand and TTL: slightly stale "online" dots in exchange for avoiding N² traffic.
- Query-time permission checks: slower than a pre-filtered index, but removal from a channel takes effect immediately.
What interviewers listen for
- A working answer: WebSocket gateway, a message store keyed by channel, a search service and a presence cache.
- A strong answer: stores each message once per channel, derives unread counts from read cursors, sizes live fan-out by attentive readers rather than members, and keeps search indexing off the write path.
- A standout answer: also names the N² presence trap and fixes it with demand-driven subscriptions and TTLs, enforces permissions at query time, treats giant workspaces as their own shards, and explains how channel order is kept with a single writer per channel.
Check your understanding
Common mistakes
Designing it as WhatsApp with a longer member list. Copying each message into every member's inbox works for a group of 50 and collapses for a channel of 50,000. Name the shift from inbox to channel log.
Storing unread flags per message. It turns reading into a write on every message for every user. A cursor per user per channel is one number.
Ignoring permissions in search and notifications. Interviewers often ask "what if someone is removed from a private channel?" and the answer is a query-time check, not a hope that the index is current.
Broadcasting presence. It is the quiet N² bug. If you describe presence as "publish status changes to everyone", you have designed an outage for the largest customer.
Practice
A company announces layoffs by posting in a 200,000-member channel. Within a minute, 120,000 people open the app and load that channel's history. What breaks, and what do you change?
Write your own answer first, on paper or in a note. Then compare.
Show a hint
Look at which partition every one of those reads hits, and what each client asks for first.
Show a strong answer
One partition takes all the reads. Every client fetches the latest 50 messages of the same channel, so the same partition is read 120,000 times in a minute, about 2,000 reads a second against a single replica set. A store can serve that, but it is the hot-key pattern. Put a short-lived cache in front of "latest page of a channel", keyed by channel ID, with a TTL of a second or two. Almost all those reads become cache hits.
The pattern worth keeping: a sudden audience for one object is a hot-key problem, solved with a short cache, coalesced writes and batched events.
The interviewer asks for threads: replies to a message that show in a side panel and optionally in the channel. How do you model them, and what happens to unread counts?
Write your own answer first, on paper or in a note. Then compare.
Show a hint
Decide whether a reply is its own message and how it relates to the channel's ordering.
Show a strong answer
A reply is a message with a parent. Store it in the same channel partition with its own ts and a thread_ts pointing at the parent. The channel keeps one ordering, and a thread is a filter on thread_ts. A separate "thread replies" index keyed by (channel_id, thread_ts) makes loading the side panel one range read.
Unread counts need two cursors. Channel unread counts only top-level messages and flagged replies. Each thread has its own last_read_ts for people who follow it, and a reply notifies only the thread's participants and followers, not the whole channel.
The pattern worth keeping: add structure as extra keys on the same log, not as a second copy of the data, and give each new notion of "unread" its own cursor.
Key takeaways
- The unit changes from the inbox to the channel. Store each message once, in the channel's partition.
- Pay fan-out per attentive reader, not per member: full events to viewers, badge events to the rest.
- Derive unread state from a per-user cursor and the channel's latest
ts. - Presence is quadratic if you broadcast it. Subscribe on demand and expire by TTL.
- Search is asynchronous but permissions are checked at query time.
- One owner per channel assigns order, and giant workspaces get their own shards.
Further reading
- I. Fette and A. Melnikov, RFC 6455 "The WebSocket Protocol" (2011): the framing under every live channel event.
- G. DeCandia et al., "Dynamo: Amazon's Highly Available Key-value Store", SOSP (2007): partitioning and availability trade-offs for message history.