Data

Database index

Like the index at the back of a book, it lets the database jump straight to matching records instead of reading every one, and it can forbid duplicates outright.

Updated October 2026 · with examples from our own builds

What does database index mean in practice?

Without an index, a query reads every record to find matches; with one, it goes straight to them. Indexes also enforce rules: a unique index makes it impossible to store two records with the same key.

The first time most founders hear about indexes is when an app that was fast with test data slows down with real data. They matter for money too, because a unique index is often the last line of defence against a duplicate invoice or a webhook processed twice.

None of this is free. Each index takes storage and slows writes slightly, and some query types, such as distance searches, need a particular kind of index and data stored in a particular format.

Database index at a glance

Speeds up
Searches and sorts on large collections
Also enforces
Uniqueness, such as one invoice per order
Cost
Storage and slightly slower writes

Where has database index come up in our builds?

A unique index stops two invoices being issued for one Razorpay order; the gapless numbering rests on the write order and unique indexes rather than on a multi-document transaction.
AskForth (built, not launched)
Unique indexes on the audit log's sequence number and hash turn any race past the writer's lock into a retry rather than a fork in the chain, and there is deliberately no expiry index, because entries are kept for at least six years.
Temphera (built, not released)
MongoDB's distance queries need GeoJSON points with a 2dsphere index, but Trainr stores latitude and longitude as separate fields on five models. While the trainer list is small, distance is scored in memory, and the next step is written down: a GeoJSON point beside each location, a 2dsphere index and $geoNear.
Trainr

Common questions about database index

Why is my app fast in testing but slow with real users?

Often a query that reads every record because no index covers it. Small test data hides that, so ask your team which queries run on every page load and whether each one has an index.

Can the database itself stop duplicate payments?

A unique index on the payment or event ID makes a second copy impossible to save, which is a strong backstop behind the application's own checks.

Related terms

Sources

Planning a product and not sure where database index fits? Ask us, or browse all 116 terms in the glossary.