Search: Cheap Retrieval, Expensive Ranking, Split Across Two Tiers

Why Search Is Split in Two

A search engine ranks by properties of the document — term frequency, field matches, recency. But in Slack, the best predictor of whether a message is the one you want has almost nothing to do with the message text:

Signal Slack found importantLives where?
Message ageIn the index — cheap for Solr
Lucene score of the message against the queryIn the index — cheap for Solr
The searcher's affinity to the message's authorSlack's social graph — per searcher
Priority of the searcher's DM channel with the authorYour behaviour — per searcher
The searcher's priority score for the channel it appeared inYour behaviour — per searcher
Whether the author is the searcherTrivial to compute — but only per searcher
Whether it was pinned, starred, or reacted toMutable state, changes after indexing

That is the list Slack published as the most significant features of a ranking model (an SVM) trained on search-click data. Four of seven are per-searcher — the same message ranks differently for two people in the same channel. You cannot bake that into a shared index, because there is no single correct score to store. And one more is mutable: a pin or a reaction added an hour after indexing would need a re-index to be visible to Solr, but is just a lookup for the application. So the split is: use “Solr's custom sorting functionality to retrieve a set of messages ranked by only the select few features that were easy for Solr to compute,” then re-rank in the application. Slack reported the result as 9% more searches with a click, and 27% more clicks at position one among them.

Two-stage retrieval in Slack search, drawn as a funnel whose bar width is log-scaled to the number of candidates. At the top, a full-width purple bar: every message in the workspace’s Solr index, millions of them. All of it feeds stage one, Solr retrieval, which is cheap but has to touch the whole index: a custom sort on the only features Solr computes cheaply, message age and the Lucene score of the message against the query. Its cost is tiny per document multiplied by millions of documents. Three orders of magnitude fewer come out: a much narrower bar holding a few hundred candidates instead of millions. Those few hundred feed stage two, re-ranking in the application, which is expensive and different for every searcher: an SVM trained on search-click data over the features no index can hold — your affinity to the author, the priority of your DM with them, your priority for the channel, whether the author is you, and whether the message was pinned, starred or reacted to after it was indexed. Its cost is expensive per candidate but multiplied by only a few hundred candidates. The narrowest bar at the bottom is the page of twenty results you actually see. Slack measured the split as 9 percent more searches with a click and 27 percent more of those clicks at position one. Four of the seven features are per-searcher and one changes after indexing, so a shared index has no single correct score to store; the index supplies recall and the application supplies precision, because expensive scoring is affordable once the candidate set is small.
Two-stage retrieval: cheap and wide, then expensive and narrow

The pattern is worth naming because it recurs everywhere in ranking: use the index for recall — get the right few hundred out of millions — and the application for precision — order those few hundred using signals the index could never hold. Expensive scoring is affordable once the candidate set is small.

The Permission Problem

Search has a constraint most ranking systems don't: every result must be one this specific user is allowed to see. Their channels, their DMs, their private groups — and membership changes constantly. Slack's search post does not say how it enforces this, so what follows is the standard analysis rather than a description. There are only two places to enforce it, and both have a real cost:

Pre-filter (in the query)Post-filter (after retrieval)
HowConstrain the search to the user's channel IDsRetrieve broadly, then drop what they can't see
CorrectnessExact — forbidden documents are never retrievedExact, if the filter is right
CostThe user's membership set goes into every query; a user in 500 channels makes a large queryWasted retrieval work on documents that get discarded
PaginationClean — page 2 means page 2Broken — you can't know how many to fetch to fill a page of 20 after filtering

And Then Shared Channels Arrive

On that reading — the index partitioned the way the database was — search inherits every property of the workspace sharding part: perfect isolation, easy per-customer deletion and export, a bounded corpus, and a blast radius of one tenant. They also inherit the same wall. A message in a channel shared between A and B must be findable by members of both — so it is indexed twice under two retention policies, or once somewhere neither workspace exclusively owns.

Search didn't have a shared-channel problem of its own. It inherited the workspace sharding part’s, because it was built on the same assumption. That is the real cost of a load-bearing architectural assumption: when it breaks, it breaks in every system that quietly depended on it.

  • Guarantees: Ranking can use signals that don't exist in the index and change after indexing, because final ordering happens in the application where all of Slack's data is reachable.
  • Does not guarantee: That a message ranked highly for one user ranks highly for another — most signals are per-searcher — nor that a result is instantly findable, since indexing is asynchronous (see async work) and lags the message by however long the queue is.