Flannel: An Application-Level Cache at the Edge
What It Is
Flannel is a caching service that sits in front of the Gateway Servers, deployed at edge points-of-presence around the world. The client no longer connects to Slack's core; it connects to Flannel, and Flannel maintains its own upstream WebSocket to the main AWS infrastructure.
Two details are worth pinning down, because the two Slack posts describing this tier are six years apart. The 2017 Flannel post has the client's socket terminating at Flannel, with Flannel opening “a WebSocket connection to Slack servers in the main AWS region to stay current by consuming real-time events” — one upstream subscription serving many local clients. The 2023 real-time messaging post describes the socket path as client → Envoy → Gateway Server and does not mention Flannel at all. Whether Flannel still sits in the socket path or has become a bootstrap-and-query service beside the GS is not published; the mechanisms below hold either way, because all of them depend on Flannel consuming the event stream, not on where the socket terminates. Nor does the Flannel post say what happens on a miss — the only sensible reading is that Flannel asks the core (the Webapp, and through it MySQL) and caches the answer, which is what the cold-start weakness at the end of this part assumes.
The Four Mechanisms
-
Lazy loading replaces the snapshot. On connect, the client gets a minimal bootstrap — enough to render the sidebar and the current channel — instead of the full workspace. Everything else is fetched on demand through query APIs: "give me profiles for these 40 user IDs." The cost function flips from O(workspace) to O(what's on screen).
-
The cache invalidates itself, because it is a subscriber. Flannel holds a WebSocket upstream and consumes the same real-time event stream that clients do. When a user changes their avatar, the
user_changeevent flows out through the normal fan-out — and Flannel is one of the recipients. It updates its cached copy from the event. 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. -
Consistent hashing gives team affinity. Users of the same workspace, connecting from the same network region, are routed to the same Flannel instance — the hash is on the team and is applied at the edge, before a socket is assigned. Since a workspace's members overwhelmingly query the same few thousand objects — their colleagues, their channels — one user's fetch warms the cache for the next. The hit rate is high for exactly the reason the workspace sharding part is about: workspaces are tightly bounded working sets.
-
Predictive push turns a future miss into a prefetch. Flannel sees the message event before the client does. So if a message references a user the client hasn't loaded, Flannel pushes that user's profile ahead of the message. The client never experiences the miss. This is only possible because Flannel is on the event path, not beside it.
Ordinary caches are placed beside the data path and must be told when to expire. Flannel is placed on the event path, so freshness is a side effect of doing its job. That is why it can be thousands of miles from MySQL and still be correct.
The Numbers
| Payload reduction | 7× on a 1,500-user team; 44× on a 32,000-user team |
|---|---|
| Simultaneous connections | 4 million at peak (as reported at the time of the post) |
| Query load | 600,000 client queries per second |
Read the first row again with the boot payload part’s cost function in mind. The reduction multiplier grows with team size — 7× then 44× — which means Flannel didn't shave a constant off the payload, it changed the exponent. Before: cost per connect ∝ workspace size. After: cost per connect ∝ working-set size, which is roughly constant regardless of how big the company is.
The Layer Flannel Does Not Add: Reconnect as a Diff
Three separate things make a connect expensive, and they are routinely collapsed into one. Flannel addresses the first two. The third is a different question entirely, and it is the one the phrase “just opened the laptop lid” is really pointing at:
| Axis | The question it answers | Cost per connect afterwards | Where |
|---|---|---|---|
| Scope | What does this user need, rather than this workspace? | O(working set) | The boot payload part’s reframe, this part's lazy loading |
| Locality | How do I make forty small fetches cheaper than one fat one? | O(working set), at edge RTT and off the origin shard | this part's Flannel |
| Persistence | What does this client not already have? | O(what changed since it last looked) | Not published — reasoned below |
The second axis is what makes the first one viable: at 150 ms of round-trip time, forty sequential fetches are worse than one three-megabyte download, so lazy loading only works once the fetches are local. That dependency is why this part had to follow the boot payload part rather than replace it.
The third axis starts from an observation neither of the first two uses: a lid-open is a re-connect. This client held all of this data twenty minutes ago. The fatal property of a snapshot is that it is valid only at the instant it was taken, so none of yesterday's copy can be reused — which is precisely why the boot payload part’s third failure (“every reconnect pays the whole price again”) is the one that actually generates storms. Persisting the client's store across boots is easy; knowing whether it is still right, cheaply, is where the real difficulty is.
Never make the client prove what it holds. The obvious protocol — the client uploads “here are the 800 channel IDs and 4,000 user IDs I have, at these versions” — is O(cache) on the upload. The quadratic has not gone away; it has changed direction. What works is a cursor: the workspace's changes are an ordered log, the client remembers where it stopped reading, and reconnect is a single question — what changed after X? The cost is proportional to elapsed change, not to cache size and not to workspace size. It needs a retention window and a “cursor too old → refetch the working set” fallback, and that fallback is what keeps the design honest: it is exactly this part's behaviour, now confined to clients that slept for a week.
Render stale, correct in place. Paint rungs 2 and 3 from the local store before the network answers, then let reconciliation fix what is wrong. Perceived boot goes to roughly zero and the real work leaves the critical path. You pay in flicker — a channel name or an avatar visibly changing a beat after it appeared — and in one hard rule: anything outbound or destructive (marking a channel read, sending, editing) must wait for authoritative state, or a stale view will cheerfully mark unread messages as read.
Badges are two scalars; history is not. An accurate unread badge on 200 channels does not need a single message. It needs
last_read_tsfrom your membership row and the channel'slatest_ts— a comparison of two numbers, a few kilobytes for the entire sidebar. That is why the What Slack is part’s membership table is the boot-critical structure and messages is not, and it is the cleanest instance of the general move: pick a representation in which the expensive rung can be skipped rather than optimised.Subscribe first, then backfill — in that order. A socket tells you what arrives after you attach and says nothing about what you missed while it was shut; the client cannot detect the hole on its own. So attaching must be: open the subscription, then fetch history from the last
tsyou hold (conversations.historywitholdest), then de-duplicate the overlap. Reverse the order and there is a window between “backfill finished” and “subscription live” in which events vanish silently — and only under load, which is exactly when you will never reproduce it. The deliberate overlap, and the de-duplication it forces, are the price of never losing a message.
Put the four together and the storm ladder from the boot payload part gets one more rung — the only one whose cost is independent of both the herd size and the customer's size:
| What a client does on reconnect | N clients reconnecting together |
|---|---|
Full snapshot (rtm.start) | O(N²) bytes and DB reads, concentrated on one shard (see workspace sharding) |
| Full snapshot + jittered backoff | Still O(N²) — the same work, stretched over a longer window |
| Working set from the edge (Flannel) | O(N) at the PoP; the origin sees only the misses |
| Cursor diff against a warm local store | ≈ O(change during the gap) — for a twenty-minute lid-close, near zero |
- Guarantees: Connect cost is bounded by the user's working set rather than the workspace's size, and cached objects converge to fresh automatically because invalidation rides the same event stream as delivery.
- Does not guarantee: A cold Flannel instance is fast. After a PoP restart or a ring change, affinity is lost, hit rates collapse, and queries fall through to the core — the storm is deferred to the cache tier, not abolished. Nor does it exploit the fact that a reconnecting client already has most of the answer: the working set is re-fetched from scratch on every lid-open — cheaply, but needlessly. And it does nothing for fan-out (see channel fan-out): it makes connecting cheap, not receiving.