Quick revision
The short answer
PostgreSQL full-text search with a tsvector column and a GIN index adds no new system, stays transactionally consistent, and suits modest relevance needs when the data lives in one database. Hibernate Search gives entity-centric indexing with little code and fits a single JPA application that owns its data. A separate search service fed by change data capture fits many data sources, demanding relevance, high scale and independent scaling. We weigh operational cost, language analysis, faceting and consistency, start with the simplest option that meets the relevance needs, and plan the path to the next one.
What to remember
In this answer, we compared three ways to add search. PostgreSQL full-text search with tsvector and GIN adds no system and stays transactional, fitting modest relevance needs in one database. Hibernate Search indexes JPA entities with little code for a single application that owns its data. A CDC-fed search service handles many sources, complex relevance and independent scale at the highest operational cost. We chose by operational cost, language analysis, faceting and consistency, starting simple with a planned path forward.
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.
PostgreSQL full-text search with a tsvector column and a GIN index adds no new system, stays transactionally consistent, and suits modest relevance needs when the data lives in one database. Hibernate Search gives entity-centric indexing with little code and fits a single JPA application that owns its data. A separate search service fed by change data capture fits many data sources, demanding relevance, high scale and independent scaling. We weigh operational cost, language analysis, faceting and consistency, start with the simplest option that meets the relevance needs, and plan the path to the next one.
Why this question is asked
Search is a feature where teams often over-build: a search cluster, a pipeline and a new on-call rotation for a box that searches 50,000 rows. Others under-build and end up with like queries timing out. Interviewers ask this design question to see whether we can choose by criteria and explain what each choice costs over time. In this answer, we will recap what each option is, go through the criteria that separate them, show what each looks like in code, and finish with how to start simple and migrate when needed.
1A Quick Recap of the Three Options
PostgreSQL full-text search works inside the database. A tsvector is a column type holding a document's normalized words, produced by to_tsvector with a language configuration that handles stemming, so running and runs both become run. A GIN index, a generalized inverted index, maps each word to the rows containing it. Queries use a tsquery and the @@ match operator, and ts_rank orders results by relevance.
Hibernate Search is a library inside our JPA application. It maps entities to documents in Lucene or Elasticsearch and updates the index from Hibernate's entity events.
A separate search service is its own deployable, usually backed by Elasticsearch or OpenSearch, fed by change data capture, CDC: a tool such as Debezium reads the database's change log, its write-ahead log in PostgreSQL, and publishes every change, typically through Kafka, to an indexer that builds the search documents.
- PostgreSQL FTStsvector column + GIN index in the same database
- Hibernate Searchlibrary in the app, index in Lucene or Elasticsearch
- Search service via CDCDebezium -> Kafka -> indexer -> search cluster
3 layers, from the top down. Step through them one at a time.
From least to most infrastructure.
2PostgreSQL Full-Text Search: No New System
The strongest argument for PostgreSQL search is what it avoids. There is no second system to run, secure, back up or keep in sync. A generated column keeps the tsvector up to date in the same transaction as the row, so search results are always consistent with the data, including after bulk updates and changes from other applications.
Its limits are relevance and features. Ranking is basic compared with a search engine, typo tolerance needs extra extensions such as pg_trgm, faceted counts over many fields get expensive, and search load competes with transactional load on the same database. For an internal tool, a catalogue of tens of thousands of products or a help centre, it is often all we need.
3Hibernate Search: Entity-Centric With Little Code
Hibernate Search fits when one JPA application owns the data and wants richer search than PostgreSQL offers, such as better analyzers, fuzzy matching, facets and highlighting, without building a pipeline. We annotate entities and the library keeps the index in sync.
The costs are an index backend to run, Elasticsearch for multi-instance deployments, and the synchronization limits that come from listening to entity events: bulk updates, native SQL and other applications' writes do not reach the index without extra work, and crash-safe indexing needs the outbox-polling strategy.
4A Search Service Fed by CDC: Scale and Many Sources
A separate service fits when the search document combines data from several services or databases, when relevance is a product in itself with tuning, synonyms and per-market analyzers, when query volume is high enough that search should scale independently, or when a dedicated team owns search. CDC reads the database log, so it sees every committed change, including bulk updates and external writes that Hibernate Search would miss.
It is also the most expensive option. We run Debezium, Kafka, an indexer and a search cluster, handle schema changes in the pipeline, reprocess history when the document shape changes, and accept eventual consistency, typically seconds of lag, in the user experience.
5Comparing the Criteria
Putting it side by side helps the conversation with product owners, because each criterion turns into a question they can answer: how good must ranking be, which languages, do we need facets, how stale may results be, and who will operate it?
| Criterion | PostgreSQL FTS | Hibernate Search | Search service + CDC |
|---|---|---|---|
| New infrastructure | None | Index backend | CDC, Kafka, indexer, cluster |
| Consistency | Transactional | After commit; bulk needs reindex | Eventual, seconds of lag |
| Relevance and typos | Basic; pg_trgm for fuzzy | Good analyzers, fuzzy | Full control, tuning team |
| Facets and aggregations | Possible, costly at scale | Supported | Supported, scales well |
| Data sources | One database | One JPA application | Many services and stores |
| Scaling | With the database | With app plus backend | Independent |
6Start Simple, Plan the Path
Our default recommendation would be to start with the simplest option that meets today's relevance needs, and write down the trigger for moving on. For many teams that is PostgreSQL full-text search, with a trigger such as relevance complaints, the need for facets across millions of rows, or search load above a few percent of database CPU. The step to Hibernate Search is small for a JPA application. The step to a CDC-fed service is larger, but it is easier if search access already goes through one interface in the code, such as a ProductSearch port with a PostgreSQL implementation, so the caller does not change when the implementation does.
7Follow-up questions
Can PostgreSQL search handle several languages?
Yes, by choosing a text search configuration per row or per column, such as english or german, and storing the language with the row. It covers stemming for many languages, but advanced needs such as decompounding German words or Asian language segmentation are where dedicated search engines are much stronger.
Why not use Hibernate Search when several services own the data?
Because it indexes from one application's entity events. Data owned by another service never passes through those events, so the index would need custom feeding anyway. At that point a CDC pipeline is the more honest design.
How do we migrate from PostgreSQL search to a search service later?
Keep search behind one interface, build the new index alongside the old one, backfill it, compare results for a sample of real queries, and switch traffic gradually with a flag. Keeping the PostgreSQL implementation for a while gives a fallback.
8Conclusion
In this answer, we compared three ways to add search. PostgreSQL full-text search with tsvector and GIN adds no system and stays transactional, fitting modest relevance needs in one database. Hibernate Search indexes JPA entities with little code for a single application that owns its data. A CDC-fed search service handles many sources, complex relevance and independent scale at the highest operational cost. We chose by operational cost, language analysis, faceting and consistency, starting simple with a planned path forward.
Open with
I would choose by criteria and start with the simplest option that meets the relevance need. PostgreSQL full-text search, a generated tsvector column with a GIN index, adds no new system and is transactionally consistent, so even bulk updates and other writers are covered.
Then, if they want more
It is good for modest relevance needs when the data lives in one database, like an internal tool or a medium catalogue, but ranking is basic, fuzzy matching needs pg_trgm, and search load lands on the main database.
Hibernate Search fits a single JPA application that owns its data and wants better analyzers, fuzzy matching and facets with little code; the costs are running a backend like Elasticsearch, and the limits of entity events: bulk updates and external writes do not reach the index without extra work.
A separate search service fed by CDC, Debezium reading the write-ahead log into Kafka and an indexer, fits when documents combine several sources, relevance needs real tuning, or search must scale on its own, at the highest operational cost and with eventual consistency.
I would also weigh languages, facets and staleness tolerance, keep search behind one interface, and write down the trigger for moving to the next option.
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
- Spring Data JPA reference, Hibernate ORM documentation, Spring Framework reference, Transaction management
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 "Should your teams use Hibernate Search, PostgreSQL full-text search (tsvector with GIN)...": https://scrivio-interview-library.netlify.app/databases/jpa-queries/04adc021d2/