Skip to content
About
Main content
Bytes at Rest

Indexing

When does a separate "where is it?" structure pay for itself, and what does it cost to keep it true?

Who this mechanism is for: a developer who writes code, calls APIs and knows basic SQL (SELECT, WHERE, JOIN, CREATE INDEX), but has never studied how a database finds a row, why an index is sometimes ignored, or why adding an index can slow a system down. You do not need to know B-trees, , sharding or vector search beforehand. Every technical term is explained the first time it appears, and again in the glossary at the end.

The story we will follow

Priya is a backend engineer at Parcelo, a company that tracks parcels for online shops. Customers see where their parcel is, couriers see which pickups are waiting, and support staff search for lost items. The main database holds a parcels table with 100 million rows and an events table with several billion rows (each scan, hand-over or delivery attempt is one event). Tomás is the senior engineer who owns the database and is always on call.

Over four parts, Priya will meet four problems. Each one looks like a bug: an index that exists but is not used, a query that gets slower after "fixing" it, a map search that scans everything, a search that returns stale answers. Each one is actually a consequence of how indexes work. Every article opens with her problem and ends with the solution, written in a section called "Back to Priya".

The main idea of this mechanism:

How this mechanism is organized

After that: a summary, hands-on labs, interview questions and a glossary.

One request: do not skip the arithmetic. Almost every rule people memorize about indexes ("", "5% ", "put the selective column first") is the result of a short calculation. If you can redo the calculation, you do not need to memorize the rule, and you will know when the rule is wrong.

A note on scope. This mechanism is about the map from a key to a location, and the cost of keeping that map true. It asks: what does an index map from and to, can a given predicate (the WHERE condition) be answered by (skipping data) at all, and what does the write path pay? It does not explain the internal code of each data structure, how text is split into words or scored, or how a builds its statistics in detail. Where those matter we give the short version we need.

What do I do, and what does each option cost?

Can I see it myself?

Can I reason about it under questioning?

Trade-offs

The tensions this mechanism takes a position on. Each recurs across mechanisms.

Show all 8 trade-offs
Recurring principles

Ideas this mechanism meets that keep coming back, mechanism after mechanism.

Show all 8 principles