What Slack Actually Is
How Slack keeps tens of millions of persistent connections fed with sub-second messages, decides who gets a green dot, and stores it all in MySQL — and why the single decision that made all of that simple (one workspace, one shard) is also the decision that made shared channels take three years and a database migration to ship.
Before any mechanism, get the shape right. Four facts define everything downstream:
| Tenancy | A workspace (Slack's code calls it a team) is a near-total boundary. Users, channels, messages, files, search — all scoped inside one. |
|---|---|
| Latency target | Slack states that its system “delivers messages across the world in 500 ms.” That is a product promise, not a stretch goal — chat that lags feels broken. |
| Connection scale | Tens of millions of simultaneously connected clients, each holding an open socket, most of them idle most of the time. |
| Durability | Every message is stored and searchable, by default forever. Delivery may be best-effort (see Gateway and Channel Servers); storage never is. That is the whole reason there is a second axis to this guide: something has to hold a decade of every company's conversations and answer queries on it. |
"Workspace" — What the Word Actually Means
A workspace is one customer's private installation of Slack — acme.slack.com. In the database it is a row with a team_id, and nearly every other row Slack stores carries that team_id as a column. Signing in to Acme's Slack is not entering a room inside one global Slack; it is entering a self-contained world:
| Inside the boundary | Its users and their profiles, its channels (public, private, DMs), every message ever posted in them, files, custom emoji, integrations, admin settings — and, on the natural reading of the search part, its own slice of the search index. |
|---|---|
| Shared across workspaces | Almost nothing that matters. One human's Slack account can belong to many workspaces, but in each one they are effectively a separate user with a separate ID, profile, and message history. The two deliberate exceptions are products, and both are the cross-shard wall part’s subject: Slack Connect (a channel shared between two companies' workspaces — Acme and its vendor in one #acme-globex) and Enterprise Grid (one organisation made of many workspaces, with users and channels that span them). |
| Size range | A three-person startup and a 50,000-seat enterprise are the same kind of object, four orders of magnitude apart. Hold onto that — it is exactly why the workspace sharding part has a ceiling. |
Two consequences follow, and they are the whole guide. First, a query like "show me #general" never needs to look at data outside one workspace, and a bad row in Acme's data is structurally invisible from Globex — which is what lets the workspace sharding part store everything in ordinary MySQL. Second, the day a feature needs one channel to belong to two workspaces, that boundary has no answer, which is the cross-shard wall part.
Everything Is a "Channel"
This one is a vocabulary trap, so start by separating the two meanings of the word.
| Channel, in the product | A room people chat in. #general, #incidents. This is what the word means to a user, and it is not what it means in the code below. |
|---|---|
| Channel, in the real-time tier | A topic you can subscribe to — a named mailbox that events get published into and that connected clients can ask to receive. Nothing about it implies humans, rooms, or chat. |
A chat room is one such topic. But so is a user (topic: "things that change about U123"), a file, a whole workspace, a huddle. This is Slack's own framing, not the guide's: a “channel,” it says, “is an abstract term whose ID is assigned to an entity such as user, team, enterprise, file, huddle, or a regular Slack channel.” Anything the UI needs to keep fresh gets a topic.
Why bother — what the alternative would cost
Picture building this the obvious way. Message delivery clearly needs a real-time path, so you build one. Then typing indicators arrive: different data, different recipients, so you build a second path. Then presence, reactions, profile edits, file renames, channel renames, emoji uploads, admin setting changes. Each one is its own small delivery system — its own subscriber bookkeeping, its own fan-out loop, its own batching, its own bugs, its own separate scaling story. You now have dozens of half-built message buses, and the hundredth feature costs as much as the first.
The reframing collapses all of that. If every one of those is just publish an event into a topic, then there is exactly one routing mechanism in the entire real-time tier, and every new feature is a new event type on the existing path rather than new infrastructure. Slack says it moves hundreds of event types this way, all through the same code.
The table below names topics like C456 and U123, so a word on those first. Everything in Slack has an ID, and the first letter says what kind of thing it is — C for a channel, U for a user, T for a team (workspace), F for a file, D for a DM. Real ones are longer, like C0123ABCD; this guide uses short fakes so they are readable.
The distinction that matters: #general is a display name — it can be renamed tomorrow, and every workspace on Slack has one. C456 is the identity, unique and immutable. Slack routes on the ID and never on the name, which is why renaming a channel breaks nothing at all: the hash of C456 is unchanged, the same server still owns it, every subscription stays valid. The name is a label stuck on a topic, not the topic.
Two more words that later parts lean on without stopping to define them:
| DM | A direct message is just a channel with two members (or a few, for a group DM). It gets its own ID prefix so the UI can treat it differently, but in the real-time tier and in the database it is the same kind of row and the same routing as #general. So when the cross-shard wall part says message data was resharded “by channel ID,” DMs came along for free. |
|---|---|
| Thread, and thread subscription | A thread is the chain of replies hanging off one message. Being subscribed to a thread — because you started it, replied in it, or were mentioned in it — is a durable per-user row: a saved (user, thread) record in the database, written once when you join the thread and kept until you unfollow, not something recomputed each time a reply arrives. It is what makes later replies light up your badge without you being in the channel view. There is one such row for every user–thread pair, so a busy user accumulates tens of thousands of them. “The Four Tables Underneath,” below, lays these rows out next to membership, messages and reactions. The channel fan-out part counts them as part of the per-recipient bill; the async work part’s outage is what happened when a job tried to delete all of them at once. |
| What happens in the product | Topic it publishes to | Who is subscribed |
|---|---|---|
Someone posts "hello world" in #general | the channel C456 | Connected members of #general |
| Someone reacts 👍 to that message | the channel C456 | Same set — a reaction is not a special case |
| You change your avatar or display name | the user U123 | Other people — the clients that need to redraw your face and name. Not you: what changes about you goes to observers, what is private to you (unreads, DND) travels a separate per-user stream, the Gateway and Channel Servers part |
| A file is renamed | the file F789 | Anyone with that file open |
| An admin flips a workspace setting | the workspace T42 | Every connected client in the workspace |
One caveat on the third column. Slack publishes that a user is a topic, not who subscribes to it. For the avatar row, “observers” could mean every connected client in the workspace — which is what the public user_change API event does — or only the clients currently rendering that user, the way presence works in the presence part. The row's point survives either way: the audience is other people.
Read the rows top to bottom and notice there is no column that changes mechanism. Only the topic name and the subscriber set differ. The server-side operation is identical every time:
subscribe(client, topic) · publish(topic, event) → deliver to that topic's subscribers
What this buys, and what it costs
Buys — every optimisation is shared. Make the delivery path faster once and messages, reactions, typing indicators and profile edits all get faster together; you tune one thing, not twelve. The same goes for staying fresh: anything that needs to know when data changes just subscribes to the stream chat already uses, so it gets updates for free instead of needing its own notification system bolted on.
Costs — every weakness is shared too. One path is one blast radius: a bug or a slowdown in the routing layer degrades all of real-time Slack at once, not one feature.
The subtler cost is arithmetic, and it is worth being exact about it because the rest of Axis A is built on it. First, vocabulary: everything that flows through the real-time tier is an event. A message is one kind of event; a typing indicator, a reaction and an avatar change are other kinds. They differ in what they cost, not in how they travel.
Every event, of any kind, pays a delivery bill. Publishing into a topic is not one unit of work: the servers walk the topic's subscriber list and, for each connected recipient, find the socket, serialise a copy, write it. Call that per-recipient delivery work k. One event into a topic with n online subscribers costs n × k. Per recipient it is cheap — memory lookups and a socket write, no database — and the Gateway and Channel Servers part shows how the work is spread across machines. But it is paid by every feature, because every feature publishes into these same topics.
Some events pay a second bill on top, and a message is the main one. When a message is posted, the Webapp must also go through every member of the channel — online or not — and decide what the message means for that person: does their unread count go up, were they mentioned, do their settings say to alert them, does their sleeping phone need a push. That is a different list (members, not online subscribers), a different place (the Webapp and the database, not the socket tier), and a far larger per-person cost. Call it b; the bill is members × b. A typing indicator never pays it — nobody's unread count changes because someone is typing.
That is where the shared path stops being a gift and starts being a bill. An avatar change seen by ten people is 10 × k — invisible. One message in a 50,000-person #general is a different animal on both bills. The delivery bill goes to the members who currently have a socket open — say 20,000 at midday — whether or not they are looking at the channel, since the Gateway and Channel Servers part shows a connected user is subscribed to every channel they belong to: 20,000 × k on the socket tier. The bookkeeping bill goes to everyone, online or not, because an unread count or a push decision does not care whether you are here: 50,000 × b on the database. Now the constants you never had to think about are the whole ballgame. And the cheap events are not safe either: a typing indicator in that channel pays only the delivery bill, but people type far more often than they send, so 20,000 × k many times a minute adds up to real load. The property that made the design elegant — one mechanism, no special cases — is the same property that lets a single busy channel saturate the tier.
Both bills are the rest of Axis A. The Flannel part builds the shared-freshness win into a cache; the channel fan-out part asks which of the two bills actually hurts at scale — and the answer is b, not k, which is not the one most people guess.
The Four Tables Underneath
Before the real-time tier makes sense, it helps to picture the durable data it is delivering. Four tables carry the core of chat. Slack does not publish its schema, so the columns below are the minimal shape that produces the product's behaviour, not a quoted design. The IDs follow this guide's convention: U for a user, C for a channel.
1. Channel membership — who is in which channel, and how far they have read
| user_id | channel_id | joined_at | last_read_ts | notify_pref |
|---|---|---|---|---|
U123 (Priya) | C456 | … | 1694.090 | all |
U777 (Sam) | C456 | … | 1694.050 | mentions |
U123 (Priya) | C789 | … | 1695.000 | all |
- One row per user, per channel. Priya and Sam each have their own row for
C456, and Priya has a separate row for every channel she is in. - It holds per-user state, not just a yes/no.
last_read_tsis Priya's own read position. It is why#generalis bold in her sidebar and not in Sam's, and it is the “read marker moved on another device” that the Gateway and Channel Servers part’s per-user stream carries. - Two lookups are needed: by user (“which channels is Priya in?”, to build her sidebar and her connect-time subscriptions, the Gateway and Channel Servers part) and by channel (“who is in
C456?”, for the notification traversal, the Gateway and Channel Servers and channel fan-out parts).
2. Messages — what was said, by whom, when, and where
| channel_id | ts | user_id | text | thread_ts |
|---|---|---|---|---|
C456 | 1694.001 | U123 | “deploy is broken” | null |
C456 | 1694.010 | U777 | “looking” | 1694.001 |
C456 | 1694.020 | U555 | “same here” | null |
- Grouped by channel, ordered by
ts. The main read is “the latest 50 messages inC456”: one channel, in order. That is also why the cross-shard wall part reshards message data by channel ID. tsis both the timestamp and the message ID, unique within the channel. The Gateway and Channel Servers part’s send path explains how it is minted.- Thread replies are ordinary rows in the same table. The only difference is that
thread_tspoints at the parent'sts. Sam's “looking” is a reply to Priya's message. The channel view shows the rows with nothread_ts, plus a “1 reply” summary on the parent. Opening the thread reads the rows wherethread_ts = 1694.001.
3. Thread subscriptions — which threads each person follows
| user_id | channel_id | thread_ts | last_read_reply_ts |
|---|---|---|---|
U123 (Priya) | C456 | 1694.001 | 1694.010 |
U777 (Sam) | C456 | 1694.001 | 1694.010 |
U123 (Priya) | C789 | 1695.200 | null |
This table exists because membership is too coarse for threads. Being in #general does not mean you care about every thread in it. Only the people who started a thread, replied, were mentioned, or clicked “Follow” should have their Threads badge light up. The glossary's two phrases mean this, precisely:
| “Per user, per thread” | The key is the pair. A thread does not keep one shared subscriber list with a single read position. Every follower has their own row with their own last_read_reply_ts. And every thread a user touches adds a row, so the row count is roughly users × threads each has touched. A heavy user reaches tens of thousands. That is the per-recipient bill the channel fan-out part counts, and the pile the async work part’s “forget user” job tried to delete in one go. |
|---|---|
| “Durable” | The row is written to the database and kept. It is not derived on the fly or held in a server's RAM. The alternative would be, on every new reply, rescanning the thread to work out who started it, replied, or was mentioned. That is expensive, and it goes wrong once messages are edited or deleted. Instead the row is inserted once, when you join the thread, and later replies simply look it up. It survives restarts, reconnects and switching devices. It lasts until something explicit removes it, like unfollowing or the channel being deleted. Contrast the Gateway and Channel Servers part’s subscription, which lives in a Channel Server's RAM and dies with your socket. |
4. Reactions — who reacted with which emoji, stored beside the message, not inside it
A reaction looks like part of the message. It is not an edit to it. Slack's public API shows this three ways. Adding one is its own call, reactions.add(channel, timestamp, name), which addresses the message by (channel, ts). The live event is reaction_added, not message_changed, which is the event a real edit produces. And the message never gets an “(edited)” marker. Reactions are only merged in when history is read, where each message comes back with "reactions": [{"name": "+1", "count": 3, "users": [...]}].
| channel_id | message_ts | emoji | user_id | created_at |
|---|---|---|---|---|
C456 | 1694.001 | +1 | U123 (Priya) | … |
C456 | 1694.001 | +1 | U777 (Sam) | … |
C456 | 1694.001 | eyes | U555 | … |
The unique key is (channel_id, message_ts, emoji, user_id). Why a separate table rather than a reactions list on the message row:
| A list on the message row | One row per reaction | |
|---|---|---|
| 50 people react 👍 at once | 50 read-modify-write cycles on one row. Changes are lost unless every writer takes a lock | 50 independent inserts, no contention |
| Same person clicks twice | App code must check the list | The unique key rejects the duplicate, so the call can be retried safely |
| Removing a reaction | Rewrite the list | Delete one row |
| “(edited)” and edit history | Muddied: is this change an edit or a reaction? | The message row changes only on real edits |
| “Who reacted with 👀?” | Parse a blob | An indexed lookup |
- Stored with the channel's messages. Keyed by channel, reactions land on the same shard as the messages they belong to (see workspace sharding, cross-shard wall). “Load 50 messages with their reactions” is two reads on one shard, never a cross-shard join.
- Delivered like everything else.
reaction_addedis published to the channel topicC456: same path, same subscribers as a message, exactly as the table in “Everything Is a Channel” says. Each client finds1694.001in its local view and bumps the count. Nothing is re-fetched. - A likely read-side refinement. Summing rows on every history load costs a little, so a cached per-message summary such as
{+1: 3, eyes: 1}, maintained on each change, with the rows as the source of truth, is the natural optimisation. The API is consistent with it: on a heavily reacted message,userscan be truncated whilecountstays exact.
How the four work together
Top-level message. Priya posts “deploy is broken” in
#general. One row is inserted into messages withthread_ts = null. Live delivery goes to connected clients through the Gateway and Channel Servers part’s subscription path. Badges and push notifications come from channel membership: every member ofC456is a candidate, and each one'slast_read_tsandnotify_prefdecide what they see.Thread reply. Sam replies “looking”. One row is inserted into messages with
thread_ts = 1694.001. A row(U777, C456, 1694.001)is upserted into thread subscriptions, because replying subscribes him.Who hears about the reply. The thread's subscribers are looked up. Priya is one, because she started the thread. Her unread state for that thread is bumped and her Threads badge lights, even though she is looking at another channel. The other 9,998 members of
#generalwho never touched the thread get no badge. Thread subscriptions narrowed the audience from the channel down to the conversation.Reaction. Sam reacts 👍 to Priya's message. The client calls
reactions.add(C456, 1694.001, "+1")over HTTPS, not over the socket, just like a send. The Webapp inserts(C456, 1694.001, +1, U777)into reactions; if the row already exists, nothing changes. The messages row is not touched. Only after the insert succeeds doesreaction_addedgo out on topicC456, and telling Priya that someone reacted to her message is left to the job queue (see async work). Save first, publish second, the same rule as the send path.
Membership says where you are and how far you have read. Messages hold what was said, with thread replies as ordinary rows pointing at a parent. Thread subscriptions narrow “where you are” down to the conversations you actually follow. Reactions sit beside messages as their own rows, so the message itself is never rewritten. All four are durable, per-user or per-channel rows in MySQL (see workspace sharding). None of them is the same thing as the in-memory, per-socket subscription of the Gateway and Channel Servers part.
The Two Axes of This Guide
Slack has two scaling stories, not one. They are worth separating up front because they run out of different resources, break in different ways, and get fixed by different moves — and if you read them as one story, none of the design decisions look motivated.
The split is easiest to see by asking what happens to each side when Slack simply gets bigger:
Axis A — Connections (see the parts from Gateway and Channel Servers to presence)
The question: tens of millions of laptops and phones are holding an open socket to Slack right now. How do you keep them all attached, push each one its events within ~500 ms, and — the genuinely hard part — take a client from "just opened the laptop lid" to "usable" without shipping it the entire company?
The resource that runs out: RAM and network on the live serving tier, and the bandwidth of one connect.
How it breaks: per-connection memory, boot payloads that grow with the customer, and reconnection storms where thousands of clients demand that payload at the same instant.
Axis B — Data (see the parts from workspace sharding to search)
The question: every message ever sent has to be stored somewhere, forever, and be queryable. Which machine holds it? How do you keep one customer's terrible Tuesday off another customer's database? And what happens the first time a feature needs data belonging to two customers at once?
The resource that runs out: disk, write throughput, and query capacity on a single database machine.
How it breaks: hot shards, a hard ceiling when one tenant outgrows one box, and features that no single shard can host.
Here is the same split as a reading map — which section belongs to which axis, and the one-line takeaway of each:
| Axis | Part | The move it makes |
|---|---|---|
| A — Connections | One WebSocket per client | Split "holds the socket" from "does the fan-out" so the two can shard differently. |
| The boot payload problem | Diagnose the real wall: connect cost grew with the workspace, so reconnect storms went quadratic. | |
| Flannel | Cache at the edge, and make the cache a subscriber so it never goes stale. | |
| Channel fan-out | Find the O(n) that actually hurts — per-recipient bookkeeping, not socket writes. | |
| Presence | Replace a broadcast with a subscription scoped to what's on screen. | |
| B — Data | Sharding by workspace | Buy total isolation and single-shard joins; pay with a ceiling. |
| The cross-shard wall | Move the shard key from who owns this to what this is about. | |
| Async work & the N+1 unfurl | See what deferring work costs you: the feedback signal that something is wrong. | |
| Search | Retrieve on cheap signals, rank in the app where the good signals live. |
Now the payoff. The two axes are not independent — they touch at exactly one point, and that point is the answer to the Central Question: the same instinct, draw a hard boundary around a workspace and never cross it, is what makes Axis A's caching trivially correct and Axis B's new features nearly impossible.
Concretely, take the dividend first. Slack runs servers close to its users all over the world, and on them sits Flannel (see Flannel) — a cache holding the small objects the UI needs constantly: who the people in your workspace are, what channels exist, what's in a profile. Keeping a cache fresh is normally the hard part of owning one. Here the closed box does that work for free: every object a Flannel node holds for Acme belongs to Acme, so the only thing that can change it is an Acme event — which that node is already listening for, since it subscribes to the same stream the chat clients do. Nothing outside the box can quietly make its copy wrong. The boundary is the correctness argument.
Now the interest, on the same boundary. A channel shared between two companies (see cross-shard wall) has no box to live in — it belongs to Acme and to Globex, and every table, every cache and every query in the system was built assuming exactly one owner. The assumption that made the first problem easy is the thing that has to be torn down to solve the second. One decision, paying dividends on one axis and interest on the other.
- Guarantees: Every real-time event in Slack — messages, reactions, typing indicators, profile edits, file changes — travels the same publish/subscribe path over one connection per client.
- Does not guarantee: That a workspace is a fully closed box. Shared channels, Enterprise Grid, and cross-workspace search all deliberately puncture it — and each puncture is expensive precisely because the box was assumed everywhere.