Database Indexing Basics Every Backend Developer Should Know

Indexing is one of those topics that separates an application that stays fast from one that mysteriously slows down as data grows. The good news is that the core idea is simple, and a handful of habits prevent most performance problems.
What an index actually is
An index is like the index at the back of a book. Without it, the database reads every row to find what you asked for — fine with a thousand rows, painful with a million. With an index, the database jumps almost directly to the matching rows. That is the entire benefit: avoiding full scans of large tables.
What to index
Index the columns you filter, join, and sort on frequently. Foreign keys are almost always worth indexing because they are used in joins constantly. A column in a WHERE clause on a large, busy table is a strong candidate. The columns in your ORDER BY can benefit too.
Why not index everything
Indexes are not free. Every index must be updated on every insert, update, and delete, so too many indexes slow down writes and consume storage. The skill is choosing the few indexes that serve your real query patterns rather than blanketing every column.
Composite indexes and order
When you filter on several columns together, a single composite index covering those columns can beat several separate ones. Order matters: put the most selective or most-frequently-filtered column first. A composite index on (status, created_at) helps a query that filters by status and then sorts by date — but the column order has to match how you query.
Find the queries that need help
Do not guess. Use your database's slow query log and the EXPLAIN command, which shows whether a query uses an index or scans the whole table. The phrase you are looking to eliminate is the full table scan on a large table. Fix those, and most performance complaints disappear.
Add indexes in response to real slow queries, not in anticipation of imaginary ones. Measure, then index.
Indexing well is mostly about knowing your queries. Once you can read an EXPLAIN output, the right indexes usually become obvious.