Where a secondary index puts its cost

scatter_read = max(shard_i), i in 1..N

A secondary index does not remove the lookup; it decides which side of the read and write split pays, and the payment is a network trip.

A secondary index is a second copy of the data, sorted by an attribute other than the partition key. The copy has to live somewhere, and placement decides the cost. A local index keeps each copy beside its data, so writes stay on one node while reads ask every node. A global index partitions the copy by the indexed value, so reads touch one node while writes reach two. Neither removes the work; each moves it.

A local index is a per-node sort. Each node re-sorts its own rows by the secondary attribute, so a lookup on that node is a binary search. The catch is that no node knows what another node holds. A query for every row with a given value must be sent to all nodes, each answers from its own sorted copy, and the coordinator merges the replies. The global index sorts its entries by the indexed value and spreads them across partitions by that value, independently of where the rows live. A query for one value goes to the one partition owning that range and gets a complete answer with no merge. But the row still sits where its primary key hashed, so an insert touches two partitions: data and index. Both writes must land, and that is the price.

The abstraction hides the tail. A scatter read is as slow as its slowest partition, so the p99 of the query follows the worst shard, not the average shard. Picture twenty shards behind one product search: nineteen answer fast, one is busy compacting, and the query times out. Engineers see the timeout and reach for the global index, which fixes the read. Now each product update is a cross-partition write: the primary row on one shard, the index entry on another, and both rows held until a coordinator commits. If that coordinator dies between the two writes, the index and the primary disagree, and a simple retry cannot tell which half landed. The read got faster and the catalogue got fragile, because the cost moved to the write nobody was measuring.

Derive the partition key from the query before choosing an index. If every search is scoped to one tenant, chat, or document, route by that scope, and the local index stops being a fan-out. If the query has global scope, you cannot route it, so choose local and put an aggregator in front of the nodes. Then ask what the writes can absorb. For latency-sensitive writes, keep the index local. For rare writes and read-heavy traffic, a global index is defensible, but only if you have built the failure handling for the two-node write before launch. Store a pointer rather than a copy when the indexed entry would be large, because a global index ships every entry to its partition. Name the tail you accept: fan-out latency or failed cross-partition writes.

orders of magnitude
Partitions per local lookup
20

Twenty shards turn one read into twenty calls, and the merge waits for all of them.

Partitions per global lookup
1

One partition owns the indexed range, so the read needs no fan-out or merge.

Partitions per global write
2

One insert touches the data partition and the index partition, and both must land.

Read latency under scatter
max over shards

The p99 follows the slowest shard, not the average, so one slow node sets the tail.

field note

The naive picture of a search engine is one big inverted index that answers every query from one place. Elasticsearch does not work that way. Each document is assigned to exactly one shard, and that shard holds a complete inverted index over its own documents, so a write for a document lands on its one shard.

The wall sits on the read side. A query that spans the collection must reach every shard that could match. Each shard answers from its own index, so the response is only as fast as the slowest shard it touched. One busy shard delays the whole result, and the cost of search grows with the number of shards a query must visit.

A common response is to route each query to the shard that holds its scope, which works only when the query names that scope. Otherwise the cost stays on the read path. The non-obvious lesson is that placement is not a detail: where a document lives decides whether the price is paid on reads or on writes.