Quick revision
The short answer
I would first ask what actually changes. New attributes per product category point to a flexible-attributes problem, which PostgreSQL can solve with a jsonb column and a GIN index while keeping transactions, joins and our existing tooling. Constant structural change may be a domain modelling problem that no database fixes. A document store is the better fit only if reads are mostly by product and shaped like one aggregate and cross-entity queries and constraints are rare, and even then the schema moves into code and validators, while operations, skills, backup, search integration and running a second database all have a cost.
What to remember
In this answer, we saw how to evaluate a request to move a catalog to a document store. We first find out what changes, since per-category attributes are a flexible-attributes problem and constant structural change is a modelling problem. PostgreSQL jsonb with a GIN index often gives the flexibility while keeping transactions, constraints, joins and tooling. A document store fits when access is aggregate-shaped and cross-entity needs are rare, but schema-less still means a schema in code and migrations, and the operational cost of a second database must be part of the decision, ideally settled by a short spike.
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 first ask what actually changes. New attributes per product category point to a flexible-attributes problem, which PostgreSQL can solve with a jsonb column and a GIN index while keeping transactions, joins and our existing tooling. Constant structural change may be a domain modelling problem that no database fixes. A document store is the better fit only if reads are mostly by product and shaped like one aggregate and cross-entity queries and constraints are rare, and even then the schema moves into code and validators, while operations, skills, backup, search integration and running a second database all have a cost.
Why this question is asked
'The schema changes too often' is a real pain, but it is a symptom, and the request jumps straight to a cure. As an architect our job is to find the cause, see whether the current platform can solve it, and weigh the full cost of a new database rather than only its developer experience. Interviewers ask this to see whether we can evaluate a technology proposal fairly: neither dismissing it nor accepting it because document databases sound flexible. In this answer, we will find out what really changes, look at what PostgreSQL jsonb already offers, describe when a document store genuinely fits a catalog, clear up the schema-less myth, and finish with the costs that a decision must include.
1Ask What Actually Changes
We start with the change history. Looking at the last six months of migrations on the catalog tells us which kind of change dominates. In many catalogs the answer is attributes: televisions gain refresh_rate, shoes gain width fitting, each new category brings ten new fields, and each field needs a migration, a new column and a deployment. That is a flexible-attributes problem. The core of the product, its id, name, price, category and status, barely changes.
If instead the migrations keep reshaping core entities, splitting tables, merging them back, changing what a product even is, the team probably has not settled the domain model. A document store would let them write any shape without migrations, but the confusion would move into the data: documents of five different shapes that every reader must handle. That is worth naming in the review, because the fix is design work, not a new database.
2What PostgreSQL jsonb Already Gives Us
PostgreSQL has a binary JSON type, jsonb, which stores a JSON document in a column and supports operators to query into it. We can keep the stable core as normal columns with constraints and put the category-specific attributes into one jsonb column. A GIN index, a generalized inverted index that indexes the keys and values inside the document, makes containment queries fast.
Notice what we keep: foreign keys to categories, a unique sku, a price check, transactions across product, stock and price tables, joins for reports, and all the tooling the team already runs, from backups to monitoring to the ORM. Hibernate 6 can map a jsonb column to a Map or a record with @JdbcTypeCode(SqlTypes.JSON). For many catalog teams this one change removes most of the migrations they were complaining about.
3When a Document Store Genuinely Fits
A document database is a good fit when the access pattern is aggregate-shaped: most reads and writes fetch or save one product with its variants, images and attributes as a whole, by id or by a few indexed fields. It fits when cross-entity queries are rare or handled elsewhere, for example search and filtering in a search engine, and when constraints that span entities, such as uniqueness across tables or referential integrity, are few. Catalogs with very high read volume and very varied product shapes, such as a marketplace with millions of sellers, can meet all of these.
It fits less well when the catalog is tied into pricing, inventory and orders with transactions and joins, when reports query across products, categories and suppliers, or when the team relies on database constraints to keep data correct. In those cases the move trades a migration problem for a consistency problem.
| Concern | PostgreSQL + jsonb | Document store |
|---|---|---|
| New attributes per category | jsonb column, GIN index | Natural, any field |
| Transactions with stock and price | Yes, same database | Multi-document, costlier |
| Joins and reports | SQL joins | Aggregation or a warehouse |
| Constraints (unique, foreign key) | Enforced by the database | Mostly in application code |
| Operations and skills | Existing | New cluster, new skills |
4Schema-less Does Not Mean No Schema
Every reader of the catalog expects a price to be a number and a name to exist. In a document store those expectations still exist; they move from the database into application code, into a validator such as MongoDB's $jsonSchema, or into a schema registry. Migrations also still happen. When a field changes meaning, either a job rewrites old documents or every reader learns to handle both the old and the new shape. The work is the same, but it is less visible and easier to forget, which is why teams that move for flexibility often add schema validation a year later.
So in the review we ask the team how they will validate documents, how they will version them, and how they will migrate them. If the answer is 'we will not need to', that is a risk to record.
5Counting the Full Cost
Finally, the decision has to include the costs that do not show up in a prototype. Operations: a new cluster needs backups, restore tests, upgrades, monitoring, security reviews and on-call knowledge. Skills: the team needs to learn modelling, indexing and failure modes of the new store. Integration: search indexing, the warehouse feed and change data capture all need new connectors. And during and after the migration we may run two databases for the same data, with a synchronisation path between them that is itself a source of bugs.
My recommendation would usually be a time-boxed spike: move the category-specific attributes into jsonb on a copy of production data, measure how many migrations it removes and how queries perform, and compare that with a prototype on the document store for the main read paths. We decide on the evidence. If the document store wins clearly and the team accepts the operational cost, we plan the move with a clear owner; otherwise we have solved the pain without a second database.
6Follow-up questions
How would you query jsonb attributes efficiently with ranges, such as refresh_rate above 100?
A GIN index with jsonb_path_ops helps containment queries like @> but not ranges on a value. For a frequent range filter we add an expression index, for example CREATE INDEX ON product (((attributes->>'refresh_rate')::int)), or promote that attribute to a real column if it becomes core. Search engines are also a good place for faceted filtering across many attributes.
What would make you approve the move?
Evidence that the main access patterns are aggregate-shaped reads and writes by product, that cross-entity transactions and constraints are rare or can live elsewhere, that the jsonb spike did not solve the pain, and a credible plan for validation, migration, operations and on-call. With those, the document store is a sound choice rather than a fashionable one.
Is the EAV model, entity-attribute-value tables, an alternative?
It is the old relational answer, a table of product_id, attribute_name and value rows. It avoids migrations but makes queries complex and slow and loses types. jsonb gives the same flexibility with better types and indexing, so EAV is rarely the right choice today.
7Conclusion
In this answer, we saw how to evaluate a request to move a catalog to a document store. We first find out what changes, since per-category attributes are a flexible-attributes problem and constant structural change is a modelling problem. PostgreSQL jsonb with a GIN index often gives the flexibility while keeping transactions, constraints, joins and tooling. A document store fits when access is aggregate-shaped and cross-entity needs are rare, but schema-less still means a schema in code and migrations, and the operational cost of a second database must be part of the decision, ideally settled by a short spike.
Open with
I would start by asking what actually changes. If the migrations are mostly new attributes for new product categories, the core is stable and only the attributes vary.
Then, if they want more
PostgreSQL can handle that with a jsonb column for the category-specific attributes and a GIN index, so we keep normal columns and constraints for sku, price and category, transactions with stock and pricing, joins for reports and all our tooling.
If instead the core model keeps being reshaped, that is a domain modelling problem, and a schema-less database would just spread the confusion into the data. A document store is a good fit when reads and writes are mostly one product as a whole, by id, and cross-entity queries and constraints are rare or handled by search.
I would also point out that schema-less does not mean no schema: validation moves into code or a $jsonSchema validator and migrations still happen. Then there is the cost: a new cluster to operate, back up and secure, new skills, new connectors for search and the warehouse, and possibly two databases during migration.
I would propose a short spike with jsonb on real data, compare it with a document store prototype, and decide on the evidence.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Hibernate 6
- 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
- Redis documentation, MongoDB 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 "A team wants to move a product catalog from PostgreSQL to a document database because...": https://scrivio-interview-library.netlify.app/databases/nosql-fundamentals/7bd161979f/