Self-Test
Question 1
Why does fan-out become a scaling problem for large channels — given that the Gateway and Channel Servers part showed delivery is a two-level tree, not a flat loop?
Show answer
Because delivery is the cheap half. The tree genuinely solves the network problem: a Channel Server sends one event per Gateway Server holding a subscriber (~200 sends for a 10,000-member channel), and each GS expands locally to its own sockets in parallel. No machine does 10,000 network round trips.
What the tree does not flatten is the per-recipient bookkeeping, which is irreducibly O(n) and hits the datastore: each member's unread count, mention/badge state, notification decision (requiring that user's preferences, mute state, DND schedule, timezone and device list), mobile push dispatch, and thread-subscription rows. None of it is shareable across recipients, because all of it is a function of the user, not the message.
And it's multiplicative, not additive: one message triggers a delivery fan-out, a notification fan-out, a push fan-out, a search-index write, and an unfurl job whose result edits the message and fans out again. Count pipelines, not recipients.
Question 2
How does Slack solve the notification-storm problem for channels with thousands of subscribers?
Show answer
There is no single fix — it's six overlapping ones, and the honest answer names the product one too:
- Subscribe, don't broadcast. A Gateway Server subscribes on behalf of the clients it actually holds — once per channel per GS, however many of its clients belong to it — and a Channel Server sends to a GS only if it has registered. Members who aren't connected cost zero.
- Batch and coalesce. Group many events into one frame — done explicitly for presence via
batch_presence_aware, and the pattern generalises. - Transient events skip persistence. Typing indicators use the identical routing path but are never written to MySQL, and losing one costs nothing.
- Thin events, fat objects. Push a compact event; let clients hydrate details from Flannel, so the expensive bytes are sent once to a cache rather than n times over sockets.
- Move bots off sockets. The Events API delivers only subscribed event types over HTTP, removing a large class of always-connected firehose consumers.
- Product guardrails. Restrict who can use
@channel, warn on large channels, rate-limit apps. Not an engineering fix — a decision to make the expensive operation harder to trigger by accident, and frequently the highest-leverage change available.
The unifying idea: make the recipient set smaller before you make the delivery faster.
Question 3
What is the N+1 query problem in link unfurling, and why is it worse here than in a typical web request?
Show answer
N+1 is 1 query for the collection plus N more, one per item, where a batch would do. In unfurling: load the message (1), then per link — look up cached metadata, check permission, fetch the page, save, edit the message (N × several).
Two things make it worse than a normal N+1:
1 — The outbound axis. Each link requires a request to a third party you don't control. One slow domain blocks a worker; without per-URL timeouts and a circuit breaker, one bad site drains the pool and now push notifications are late too, because they queue behind it.
2 — The fan-out axis. Each unfurl edits the message, and an edit is an event that fans out to all n channel members. Naive: N edits × n members = N×n deliveries for one paste. Batched: 1 edit × n. The N+1 multiplies fan-outs, not just queries — that product is what melts.
Fixes: dedupe URLs in the message; batch the metadata lookup; cache unfurls globally by URL (a public article's preview is identical for every workspace — one of the very few legitimate tenant-boundary crossings) while checking permission per workspace; timeouts and circuit breakers on outbound fetches; and emit one edit when everything resolves.
Question 4
Why is workspace-level sharding a strength for multi-tenancy but a constraint for new features?
Show answer
They are the same property. "Nothing crosses the workspace boundary" is simultaneously the guarantee and the limitation.
As a strength: one metadata lookup and then every query is single-shard — including multi-table joins and transactions, on ordinary MySQL. Blast radius is one shard. Per-tenant export, GDPR deletion, point-in-time restore, and EU data residency are all bounded operations on a known set of rows on one machine.
As a constraint: a shared channel belongs to two workspaces, so no shard can own it. Which one stores the messages? Whose retention policy applies? Whose search index has it? Whose admin can delete it? Enterprise Grid poses the same question from the other side. Slack's own framing is that these features "challenged the assumption that workspace data should live on a single shard" — the blocker was never capacity, it was that the assumption was compiled into the application's idea of where data lives.
And the ceiling: the model also fails on pure size — "what if a single team and all of their Slack data doesn't fit our largest shard?" — with no incremental remedy, and it fails first for your largest customers.
The fix was to change what the shard key means: Vitess pulled sharding out of the application, which let message data shard by channel ID rather than workspace ID. The key moved from "who owns this" to "what is this," and only then was a two-owner channel representable.
Question 5
Slack's worst early scaling problem wasn't message volume. What was it, why was it quadratic, and why did adding backend capacity not help?
Show answer
It was connecting. rtm.start returned a full snapshot of the workspace — every user, every channel, every membership — so connect cost was O(workspace size) rather than O(what this user needs). A user who talks in three channels still downloaded 30,000 colleagues.
Why quadratic: reconnects aren't independent. A Gateway Server deploy, an office losing wifi, or a timezone waking up makes N clients reconnect together, each demanding an O(N) payload → O(N²) bytes in one burst. And it self-amplifies: load slows the backend, clients time out, clients retry, the herd grows.
Why capacity doesn't help: capacity scales linearly; the storm scales quadratically. Every doubling of the customer quadruples the burst, so you are buying linear relief against a quadratic threat and will lose by definition. You must change the cost function, not the constant.
How Flannel changed it: a thin bootstrap plus on-demand object queries made connect cost O(working set) — effectively constant. N reconnects became O(N), which linear capacity can absorb. Evidence it was an exponent change, not a constant-factor one: the savings multiplier itself grew with team size — 7× at 1,500 users, 44× at 32,000.
Question 6
Flannel sits at an edge PoP, thousands of miles from MySQL, and serves user and channel objects. Why isn't it constantly stale — and what does that tell you about cache design generally?
Show answer
Because Flannel is a subscriber, not a bystander. It holds its own upstream WebSocket into the core and consumes the same real-time event stream clients do. When a user changes their avatar, the user_change event flows through the normal fan-out and Flannel is one of the recipients — so it updates its copy from the event itself.
The consequence: there is no TTL to tune and no invalidation message to get wrong, because "the data changed" and "tell the cache" are the same message. A conventional cache sits beside the data path and must be told when to expire — which is where the classic bugs live (missed invalidations, TTLs traded off against staleness, thundering herds on expiry). Flannel sits on the event path, so freshness is a side effect of doing its job.
Two supporting mechanisms: consistent hashing by team routes a workspace's members to the same instance, so one person's fetch warms the cache for their colleagues (a high hit rate for exactly the reason the workspace sharding part exists — workspaces are tight working sets); and predictive push means Flannel, seeing an event before the client does, sends the author's profile ahead of the message, converting a future miss into a prefetch.
The general lesson: if you already have a reliable change stream, put the cache on it rather than beside it. You trade a TTL you have to guess for a subscription you can verify — and the cache can then live arbitrarily far from the database. The residual weakness is cold start: after a restart or ring change, affinity is lost and queries fall through to the core.