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 important | Lives where? |
|---|---|
| Message age | In the index — cheap for Solr |
| Lucene score of the message against the query | In the index — cheap for Solr |
| The searcher's affinity to the message's author | Slack's social graph — per searcher |
| Priority of the searcher's DM channel with the author | Your behaviour — per searcher |
| The searcher's priority score for the channel it appeared in | Your behaviour — per searcher |
| Whether the author is the searcher | Trivial to compute — but only per searcher |
| Whether it was pinned, starred, or reacted to | Mutable 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.
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) | |
|---|---|---|
| How | Constrain the search to the user's channel IDs | Retrieve broadly, then drop what they can't see |
| Correctness | Exact — forbidden documents are never retrieved | Exact, if the filter is right |
| Cost | The user's membership set goes into every query; a user in 500 channels makes a large query | Wasted retrieval work on documents that get discarded |
| Pagination | Clean — page 2 means page 2 | Broken — 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.