Quick revision
The short answer
A design needs a separate search engine when queries need relevance-ranked full-text search, typo tolerance, stemming and synonyms, facets with counts, or text, filter and geo conditions combined over large data. For exact and range lookups, database B-tree indexes are better, and PostgreSQL full-text search with GIN indexes covers modest text needs. Adding Elasticsearch or OpenSearch gives up immediate consistency, because the index is a derived copy that becomes searchable after the pipeline and the next refresh, and it adds a sync pipeline, a rebuild path, lag monitoring and a cluster to run.
What to remember
In this answer, we saw that B-tree indexes answer exact and range questions while inverted indexes in Lucene-based engines answer how well a document matches, with analysis, typo tolerance, synonyms, relevance scoring and facets. A search engine earns its place when ranked text search and facets over large data are central; for filters and modest text needs, B-trees and PostgreSQL full-text search with GIN are enough. Adding one means accepting an eventually consistent derived copy, refreshed every second by default, plus a sync pipeline, a rebuild path, lag monitoring and a cluster to operate.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A design needs a separate search engine when queries need relevance-ranked full-text search, typo tolerance, stemming and synonyms, facets with counts, or text, filter and geo conditions combined over large data. For exact and range lookups, database B-tree indexes are better, and PostgreSQL full-text search with GIN indexes covers modest text needs. Adding Elasticsearch or OpenSearch gives up immediate consistency, because the index is a derived copy that becomes searchable after the pipeline and the next refresh, and it adds a sync pipeline, a rebuild path, lag monitoring and a cluster to run.
Why this question is asked
Adding a search engine is one of the most common moves in system design answers, and one of the most commonly unjustified. A search cluster is powerful, but it is a second copy of the data with its own consistency, cost and failure modes. Interviewers ask this question to see whether we know what a search engine does that a database index does not, and whether we can name the price. In this answer, we will recap how the two kinds of indexes work, list the needs that justify a search engine, show when the database is enough, explain the consistency and operational costs, and answer the follow-up about which marketplace screens should never read from the index.
1A Quick Recap: B-Tree Indexes and Inverted Indexes
A database index, usually a B-tree, keeps values in sorted order with pointers to rows. It is excellent for exact matches and ranges: price between 10 and 20, created after yesterday, email equals this. It answers whether a row matches, not how well.
A search engine such as Elasticsearch or OpenSearch is built on Lucene's inverted index. During indexing, each text field is passed through an analyzer that splits it into terms, lower-cases them, removes endings (stemming, so running and runs become run), and can add synonyms. The inverted index maps every term to the list of documents that contain it, with statistics such as how often it appears. A query is analysed the same way, the matching lists are combined, and each document gets a relevance score, by default with the BM25 formula, which favours rare terms and documents where they appear often. So a search engine answers how well a document matches, and returns the best first.
| Need | Database index | Search engine |
|---|---|---|
| Exact match, range, sort by column | ideal (B-tree) | possible, not its strength |
| Relevance-ranked full text | basic (PostgreSQL ts_rank) | ideal (BM25, boosts) |
| Typos, stemming, synonyms | limited, needs extensions | built in |
| Facets with counts | GROUP BY per facet, slow at scale | aggregations in one query |
| Transactions, read your own write | yes | no, eventually consistent |
2When a Search Engine Earns Its Place
A separate index is justified when the product's main query is a user typing words and expecting the best results first. That means relevance ranking, tolerance for typos (fuzzy matching, so iphnoe still finds iPhone), stemming and synonyms (sofa finds couch), and boosting fields such as title over description. Marketplaces and catalogues also need facets: the counts next to each brand, price band and size that update with every filter, computed with aggregations in the same query. Combine that with geo filters, such as within 10 km, and tens of millions of documents at hundreds of queries per second, and a search engine is the right tool.
3When the Database Is Enough
Many screens that look like search are really filters: orders by status and date, users by email, products by category sorted by price. B-tree indexes serve these perfectly, with transactions and no extra system. For modest text search, such as searching a few hundred thousand help articles, PostgreSQL's built-in full-text search with a GIN index on a tsvector column gives stemming, ranking and good speed. Adding a search cluster for simple filters is a common form of over-engineering: it buys eventual consistency and a new system to run in exchange for nothing the database could not do.
4What the Design Gives Up
The first cost is consistency. The index is a derived copy, and the database stays the source of truth. A change commits in the database, travels through a sync pipeline (change data capture with Debezium, or events on Kafka), is indexed, and only becomes visible to searches after the next refresh, which happens every 1 second by default. So a document is searchable a second or more after its commit, and under load the pipeline can add seconds or minutes.
The second cost is the pipeline itself. We need to build and monitor it, handle deletes and reordering, and be able to rebuild the index from scratch from the source when mappings change or the index is corrupted, usually by indexing into a new index and switching an alias. Lag from commit to searchable should be measured and alerted on.
The third cost is the cluster: nodes to size, shard and replica counts to plan, upgrades, snapshots, security, and memory and disk needs that grow with every indexed field. That is real ongoing work, which is why the need should be real first.
- Application writesto the database only
- Databasesource of truth, transactions
- CDC or outbox eventsDebezium, Kafka
- Indexermaps rows to documents, handles deletes
- Search clustersearchable after refresh, about 1 s; rebuildable
5 layers, from the top down. Step through them one at a time.
5Follow-up questions
Which screens in a marketplace should never read from the search index?
Any screen where a user expects to see their own recent change or where correctness matters: the seller's own listings right after publishing, the checkout and cart, order history and order status, payments and balances, and stock levels used to accept an order. These read from the database by key. Search serves discovery: browse, keyword search, facets and recommendations, where a delay of a second is invisible.
Can I write to the database and the search engine from the application in one request?
We can, but it is dual writing: if the second write fails or the process dies between them, the copies drift and nothing notices. An outbox table written in the same transaction, or CDC from the database log, is safer, because every committed change is eventually delivered and can be replayed.
Is PostgreSQL full-text search ever enough for a product catalogue?
For a small catalogue with simple text needs, yes, and pg_trgm adds typo tolerance. It runs out when we need rich relevance tuning, many facets with counts over millions of documents, synonyms managed by merchandisers, or high query rates that we do not want on the primary.
6Conclusion
In this answer, we saw that B-tree indexes answer exact and range questions while inverted indexes in Lucene-based engines answer how well a document matches, with analysis, typo tolerance, synonyms, relevance scoring and facets. A search engine earns its place when ranked text search and facets over large data are central; for filters and modest text needs, B-trees and PostgreSQL full-text search with GIN are enough. Adding one means accepting an eventually consistent derived copy, refreshed every second by default, plus a sync pipeline, a rebuild path, lag monitoring and a cluster to operate.
Open with
I would add a search engine like Elasticsearch or OpenSearch when the core query is people typing words and expecting the best results first: relevance ranking, typo tolerance, stemming and synonyms, facets with counts, or text combined with filters and geo over a large data set.
Then, if they want more
Those come from the inverted index and analyzers, which a database B-tree does not have. For exact matches, ranges and sorting, B-tree indexes are better, and for modest text search PostgreSQL full-text search with a GIN index is often enough, so adding a cluster just for filters is over-engineering.
What we give up is consistency: the index is a derived copy, the database stays the source of truth, and a write becomes searchable only after the sync pipeline delivers it and the next refresh, one second by default.
So we need a pipeline, ideally CDC or an outbox rather than dual writes, a way to rebuild the index from scratch through an alias switch, and monitoring of lag from commit to searchable. And it is another cluster to size, upgrade, secure and pay for.
Screens like checkout, order history or a seller's own listings should still read from the database.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "When does a design need a separate search index instead of database indexes, and what...": https://scrivio-interview-library.netlify.app/architecture/storage-and-pipelines/a1cf1ed6e6/