Quick revision
The short answer
I would decide from the search requirements, not from preference. PostgreSQL full-text search with GIN, plus pg_trgm for prefix and fuzzy matching, covers keyword search with transactional consistency and no extra system. A search engine such as Elasticsearch or OpenSearch is much stronger at relevance ranking, typo tolerance, synonyms, faceting at scale and multi-language analysis, but adds a data pipeline, eventual consistency and a cluster to run. We prototype both with real queries, and often start in PostgreSQL behind a clean search interface, moving to a search engine when ranking and faceting needs grow.
What to remember
In this answer, we compared PostgreSQL search with a separate search engine for an 80 million item catalogue. Full-text search with GIN and pg_trgm gives keyword, prefix and fuzzy matching with transactional consistency and no extra system, but is weaker at ranking, typo tolerance, synonyms, facets and multi-language analysis, and its indexes slow writes. A search engine handles those well but adds a pipeline, eventual consistency, a cluster and a second security model. We decide from written requirements and prototypes with real queries, and often start in PostgreSQL behind a clean search interface, moving when ranking and faceting needs grow.
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.
I would decide from the search requirements, not from preference. PostgreSQL full-text search with GIN, plus pg_trgm for prefix and fuzzy matching, covers keyword search with transactional consistency and no extra system. A search engine such as Elasticsearch or OpenSearch is much stronger at relevance ranking, typo tolerance, synonyms, faceting at scale and multi-language analysis, but adds a data pipeline, eventual consistency and a cluster to run. We prototype both with real queries, and often start in PostgreSQL behind a clean search interface, moving to a search engine when ranking and faceting needs grow.
Why this question is asked
Search is a feature where the first version is easy and the expectations grow fast. Product teams start with 'find items by name' and soon ask for typo tolerance, filters with counts and results that 'feel right'. Choosing too small a tool means a painful rewrite; choosing too large a tool means running a cluster and a pipeline for a feature that a few indexes could serve. Interviewers ask this design question to see whether we can turn a vague debate into criteria and a test. In this answer, we will look at what PostgreSQL can do, where it falls short, what a search engine really costs, how to decide, and the common path that keeps both options open.
1What PostgreSQL Search Can Do
PostgreSQL full-text search converts text into a tsvector, a sorted list of normalised words, called lexemes, with positions. A word like 'running' becomes 'run' through a language dictionary. Queries are tsquery values, and the @@ operator tests whether a document matches. A GIN index on the tsvector makes this fast: GIN is an inverted index that maps each lexeme to the rows containing it. The pg_trgm extension adds trigram indexes, which break strings into three-letter pieces and support LIKE '%term%', similarity and fuzzy matching on names.
The big advantage is consistency and simplicity. The index is updated in the same transaction as the item, so a saved product is searchable at once, permissions and joins work with ordinary SQL, and there is no extra system to secure, monitor and back up.
2Where PostgreSQL Falls Short
The limits appear as requirements grow. Ranking with ts_rank must compute a score for every matching row, so a query that matches 2 million of 80 million items and sorts by rank is slow, because the index finds matches but does not return them in relevance order. Typo tolerance through trigrams works for short fields like names, but not well across long descriptions. Synonyms, per-language analysers, phrase boosting and learning-to-rank are possible only in limited forms. Facets, the counts per brand, colour and price band shown beside results, mean aggregation queries over large match sets on every search.
GIN indexes also slow writes. A long description produces many lexemes, each an index entry, and on a catalogue with frequent updates the GIN maintenance and its pending list become noticeable. With 80 million items, both index size and update cost are significant.
3What a Search Engine Really Costs
Elasticsearch and OpenSearch are built for this: relevance models such as BM25, analysers per language, fuzzy matching, synonyms, aggregations for facets, and horizontal scaling. But they are a second system holding a copy of the data. We need a pipeline to feed it: change data capture from the database's log, for example with Debezium, or an outbox table that the service writes in the same transaction and a consumer forwards. The copy is eventually consistent, so a just-saved item may be missing from results for a second or more, and the pipeline needs monitoring, retries and a full reindex procedure.
We also run a cluster: capacity planning, upgrades, shard sizing, backups or snapshots, and its own security model, which must reproduce any per-tenant or per-user visibility rules that the database already enforces. That is ongoing work for a team.
6 messages in order. Play them, or step through them one at a time.
Writes stay transactional in the database; the search copy follows a moment later.
4Deciding From Requirements
We write down the requirements as concrete queries and targets: what users type, which matching they expect (exact, prefix, typo-tolerant, synonym), how results must be ordered, which facets appear, the latency target at p95, the write rate of the catalogue, how fresh results must be, and what skills the team has. Then we prototype both with a production-sized copy and the top few hundred real queries, measuring latency, relevance judged by product people on a sample, and write impact.
| Requirement | PostgreSQL GIN + pg_trgm | Search engine |
|---|---|---|
| keyword, prefix, fuzzy names | good | good |
| results visible immediately | yes, same transaction | after pipeline lag |
| relevance tuning, synonyms | limited | strong |
| facets over large match sets | slow at 80 M items | built in |
| multi-language analysis | basic dictionaries | rich analysers |
| extra systems to run | none | cluster + CDC or outbox pipeline |
5A Common Path That Keeps Options Open
In many organisations, a good path is to start in PostgreSQL for the first versions, with full-text and trigram indexes, but behind a clean search interface in the service, such as a SearchService with a query object and a result type that do not leak SQL. Product teams build against that interface. When requirements for ranking, facets or languages outgrow PostgreSQL, measured against the targets we wrote down, we add the search engine behind the same interface, feed it with an outbox or CDC, run both in parallel for comparison, and switch. If the requirements already include heavy relevance tuning and facets on day one, we start with the search engine and skip the intermediate step.
6Follow-up questions
How would you keep search results consistent with permissions?
In PostgreSQL we apply the same WHERE clauses or row-level security as everywhere else. In a search engine, we index the fields that decide visibility, such as tenant id or visibility group, and every query adds a filter on them built from the caller's identity on the server side. We test that a user from one tenant can never see another's items, and we reindex when visibility rules change.
What if the pipeline to the search engine loses an update?
That is why we use an outbox or CDC rather than dual writes from the application. Both are based on data that was committed in the same transaction as the change, so a crash cannot lose it, only delay it. The consumer is idempotent, keyed by item id and version, and a periodic job compares counts or checksums between the database and the index and repairs differences, with a full reindex procedure for disasters.
7Conclusion
In this answer, we compared PostgreSQL search with a separate search engine for an 80 million item catalogue. Full-text search with GIN and pg_trgm gives keyword, prefix and fuzzy matching with transactional consistency and no extra system, but is weaker at ranking, typo tolerance, synonyms, facets and multi-language analysis, and its indexes slow writes. A search engine handles those well but adds a pipeline, eventual consistency, a cluster and a second security model. We decide from written requirements and prototypes with real queries, and often start in PostgreSQL behind a clean search interface, moving when ranking and faceting needs grow.
Open with
I would turn the debate into requirements first. If users need keyword search, prefix matching and some fuzziness on names, PostgreSQL does that well: a generated tsvector column with weights for name, description and tags and a GIN index, plus pg_trgm for fuzzy and contains matching.
Then, if they want more
The big advantage is that it is transactional, so an item is searchable the moment it is saved, permissions are just SQL, and there is no new system. Its limits are relevance ranking over large match sets, typo tolerance across long text, synonyms, facets at 80 million items, and multi-language analysis, and GIN indexes on long text add write cost.
Elasticsearch or OpenSearch are built for exactly those things, but they bring a pipeline, an outbox or CDC, eventual consistency, a cluster to operate and a second place to enforce security.
So I would write down the real queries, latency targets, write rate, freshness needs and the team's skills, and prototype both with production-sized data and a few hundred real queries, with product people judging relevance.
Quite often the answer is to start in PostgreSQL behind a clean search interface in the service, and move to a search engine behind that same interface once ranking and faceting requirements outgrow it. If those requirements are already there on day one, I would start with the search engine.
About this answer
- Last updated
- 12 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 documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
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 "Product teams want to add search across names, descriptions and tags to a...": https://scrivio-interview-library.netlify.app/databases/indexing/7c59b5c05a/