Your application was fast when it launched. Then the data grew, and now the same queries that returned in milliseconds take seconds, pages time out, and the database CPU sits pinned while everything else waits. Nine times out of ten, the culprit is not the hardware, the framework or the cloud bill — it is missing or misused indexes. Database indexing is the single highest-leverage skill in backend performance, and it is simpler than its reputation: an index is just a structure that lets the database find rows without reading all of them.

The Book Analogy That Actually Explains It
A table without an index is a book without an index or page numbers in the back: to find every mention of a topic, you read every page. A full table scan is exactly that — the database reads every row to answer your query, which is fine at a thousand rows and ruinous at ten million. An index is the back-of-book index: a sorted structure mapping each value to the rows containing it, so the database jumps straight to the right rows. The trade-off is the same as in a book: the index takes space, and every time the text changes, the index must be updated too. Understanding that trade — reads get faster, writes pay a small tax — is the whole game.
Why Queries Slow Down as Data Grows
Slow queries rarely degrade gracefully; they fall off a cliff. At small scale, the whole table fits in memory and scans feel instant, so missing indexes hide. Growth changes the physics: scans stop fitting in cache, sorting spills to disk, and joins multiply the work. This is the same scaling wall described in our guide to system design basics — systems fail at thresholds, not gradually. The dashboard query that “suddenly” broke last Tuesday was slow for months; it just crossed the line where the scan stopped fitting in RAM.
The Indexes You Will Actually Use
Three types cover nearly all real work. A single-column index serves filters and sorts on one column — an index on orders.created_at makes “recent orders” queries instant. A composite index covers several columns together, in order: an index on (customer_id, created_at) serves “this customer’s recent orders” perfectly, while the reversed order would not — column order is the detail beginners miss and the one that matters most. A unique index doubles as a data-integrity rule, guaranteeing no duplicate emails or order numbers can ever be written. Start with these three; exotic index types are for problems you can name precisely.
How to Find the Queries That Need Indexes
Never guess. Every serious database keeps a record of its slowest work: PostgreSQL’s pg_stat_statements, MySQL’s slow query log, your ORM’s query logging in staging. Turn them on and read the top offenders by total time, not by single worst run — a 200ms query called a million times a day costs more than a 5-second report run nightly. Then use EXPLAIN (or EXPLAIN ANALYZE) on each suspect: it shows the database’s actual plan, and the words “Seq Scan” on a large table, next to a filter on one column, are the database politely asking for an index.
Adding an Index Safely in Production
Creating an index on a live, busy table needs care, because a naive CREATE INDEX can lock writes while it builds. PostgreSQL offers CREATE INDEX CONCURRENTLY, which builds without blocking writes (slower, but safe); MySQL’s InnoDB supports online DDL for most index builds. Build during lower-traffic hours anyway, watch replication lag on replicas, and verify afterwards with EXPLAIN that the planner actually uses the new index — sometimes statistics need an ANALYZE before the planner trusts it. Rollout rule: one index at a time, measure before and after, and record what you added and why, so the next engineer inherits knowledge instead of archaeology.
The Mistakes That Make Indexing Worse
Over-indexing is the mirror-image failure: every index taxes each insert and update, bloats storage, and slows backups, so a table carrying fifteen speculative indexes writes slowly for reads nobody runs. Indexing low-selectivity columns alone (a boolean flag, a status with three values) rarely helps, because the database still reads most of the table. Wrapping an indexed column in a function in your WHERE clause — WHERE DATE(created_at) = … — silently disables the index. And the classic: adding an index to fix a query that actually needed rewriting, such as SELECT * pulling megabytes of columns the page never displays. Indexes are powerful medicine; dose them by diagnosis, not by hope.
Indexes Are Not the Whole Performance Story
Once the obvious indexes exist, remaining slowness usually lives elsewhere: N+1 query patterns from the ORM issuing thousands of small queries, missing pagination on lists that return entire tables, locks held by long transactions, or an application server doing in memory what one SQL query could do in the database. Indexing is the first chapter of database performance, not the whole book — but it is the chapter that resolves the majority of “the site got slow” incidents, which is why it belongs at the top of every backend engineer’s toolkit.
A 30-Minute Index Audit You Can Run Today
You do not need a performance project to start. In half an hour: enable or open the slow query log and note the five queries consuming the most total time. Run EXPLAIN on each against production-sized data. For every sequential scan on a large table with a selective filter, note the column. Check which of those columns already have indexes — and which indexes exist that no query uses, because unused indexes are pure write tax. Fix the single worst query first, measure the change, and repeat next week. Most teams find their worst offender in the first ten minutes, and fixing it pays for the whole audit many times over.
The Bottom Line
Database indexing turns “read everything” into “jump straight there”: single-column indexes for simple filters, composite indexes in the right column order for real queries, unique indexes for integrity. Find slow queries with logs and EXPLAIN instead of guessing, build indexes safely online, and resist indexing everything. Do that, and the database stops being the bottleneck your application complains about — and starts being the quiet, fast foundation it was meant to be.
