Design Indexes & the Query Engine
This is the read path of a document database drawn on its own. The documents already live in the collection as BSON records, and replication and sharding already decide which machine holds them. What is left is the part that turns a query into a small number of disk reads instead of a full scan. An index is a separate B-tree that maps values of a field to the documents that hold them. The query engine is the piece that looks at an incoming query, considers the indexes that could serve it, and picks one. Nothing here changes what the data is. It changes how few bytes you touch to answer a question about it.
Get the altitude right before drawing a box. This design sits below the driver and the router and above the storage engine. WiredTiger stores both the collection and the indexes as B-trees on disk and hands back pages; this layer decides which pages to ask for. The interesting judgment is not "add an index," which any developer types in a second. It is which indexes earn their keep, in what field order, and how the planner chooses among several that all technically apply. Get those wrong and you either scan the whole collection on every read or you slow every write down under the weight of indexes nobody's queries use.
- 1 diagram
- 5 sections
- about 45 min
Premium lessonMongoDB interview guide
These took digging.
What candidates walked out with, from 20,000+ reports, forum threads behind logins and write-ups in Chinese. Then solved step by step.
100 companies. Checked every month.
Unlock all 100 companies$49 a year · less than $1 a week · Cancel anytime
MongoDB interview guideKnow what MongoDB asks before you walk in.
31 coding · 5 system design · 15 behavioral questions
Get their questions first.
InterviewLegend is independent and not affiliated with or endorsed by any company it covers.