Postgres vs MongoDB: Modeling Product Catalogs With Variants and Attributes
Product catalogs look like a perfect fit for documents until variants, inventory, and orders show up. Postgres and MongoDB can both model them well, but they fail in different places. Here is how to choose based on the shape of your data and the guarantees your checkout needs.
Every few years a team rediscovers the same argument. A shirt has sizes and fabrics, a laptop has RAM and a screen resolution, a mattress has firmness. Relational tables seem rigid for that and documents seem natural. So the team picks MongoDB, ships quickly, and then spends a year learning why inventory counts and cross entity reports are harder than they looked.
The opposite story happens too. A team picks Postgres, designs a pristine entity attribute value schema, and discovers that every product page needs eleven joins and every merchandiser request becomes a migration. Neither database is the problem. The question is which parts of your catalog are flexible and which parts must never be wrong.
This post walks through how a commerce catalog actually decomposes, where Postgres and MongoDB each shine, and how to decide without turning it into a religious debate.
A Product Catalog Is Not One Data Shape
The mistake in most Postgres vs MongoDB debates is treating the catalog as a single thing. It is at least four, and they have different needs.
The first is the descriptive layer: titles, descriptions, images, SEO fields, and category specific attributes. It is read heavily and varies wildly by category, so it benefits from flexibility.
The second is the variant layer: the sellable combinations of options, each with its own SKU, price, and barcode. A variant is a small, regular record with the same handful of fields every time.
The third is the transactional layer: inventory quantities, reservations, carts, and orders. It is written constantly by many actors at once, and an error costs real money, so it needs strong guarantees.
The fourth is the discovery layer: search, filtering, and faceting. This is usually not served from your primary database at all.
Once you separate these, the database question becomes four smaller questions, and the answers are not always the same.
Modeling Variants and Attributes in Postgres
Postgres gives you two tools that cover most of the catalog: normalized tables for the regular parts and JSONB for the irregular parts.
A clean pattern is a products table, a variants table with a foreign key to the product, and a JSONB column for category specific attributes on the product. Prices, SKUs, weights, and inventory references live in typed columns on the variant, where constraints, foreign keys, and unique indexes protect them. The long tail of attributes (screen size, fabric weave, wattage) lives in JSONB where adding a new attribute is a code change, not a migration.
JSONB is not a compromise bolted onto a relational engine. It is a binary format that supports indexing through GIN indexes, containment queries, and expression indexes on specific keys. If merchandisers filter heavily on one attribute, you can add a targeted index for it. You can also promote a hot attribute from JSONB to a real column later, using a generated column or a backfill, once you know it deserves one.
Variants are real rows, so uniqueness of SKUs is enforced by the database, option definitions can be validated against their own tables, and reporting across products, variants, and orders is ordinary SQL.
The weakness is that JSONB attributes have no schema unless you add check constraints or validate in the application.
Modeling Variants and Attributes in MongoDB
MongoDB's natural model is the product as a single document: descriptive fields, an array of variants embedded inside, and an attributes subdocument that varies by category. One read returns everything a product page needs. There is no join, and the shape matches what the frontend wants to render.
That is a genuine advantage for read heavy catalogs. A product detail page becomes one indexed lookup, and categories with wildly different attributes coexist in one collection without ceremony.
The costs show up at the edges. Embedded variants are great until a product has thousands of them; documents have a size limit, and large arrays make updates heavier. Teams then split variants into their own collection and reintroduce references, at which point you are managing relationships by hand. Uniqueness of a SKU across all products requires a unique index on a field inside an embedded array, and the semantics there deserve careful testing. And anything that crosses products, such as "all variants under this price with stock," needs aggregation pipelines that are powerful but harder for a general engineering team to read than SQL.
MongoDB does support schema validation using JSON Schema, and you should use it. A catalog with no validation drifts quickly: one importer writes price as a string, another as a number, and a year later nobody trusts the data.
Transactions for Inventory and Orders
This is where the decision usually gets made, whether or not teams realize it.
Postgres gives you full ACID transactions as a baseline. Decrementing inventory, creating an order, writing line items, and recording a payment intent can happen in one transaction across any number of tables. Row level locking and constraints let you say, in the database, that stock can never go below zero. The common reservation pattern, where you hold stock during checkout and release it on timeout, is straightforward to implement correctly.
MongoDB supports multi document transactions, and they work. But the document model encourages you to design so that you rarely need them: put the data that changes together inside one document, and single document updates are atomic. For inventory, that can mean an atomic decrement with a condition on the current quantity. That works well for a single counter. It gets harder when an order must touch inventory records, a customer record, and a promotion usage counter at once, because now you are leaning on multi document transactions, with the performance and retry considerations that come with them.
Neither database is incapable. The difference is the default posture. In Postgres, correctness across entities is the easy path and flexibility takes deliberate effort. In MongoDB, flexibility is the easy path and cross entity correctness takes deliberate effort. For a catalog, flexibility is cheap to add later. For an order system, correctness is expensive to retrofit.
If your checkout runs on a commerce platform such as Shopify or commercetools, this is partly moot, because the platform owns orders and inventory. Your own database then holds the enriched catalog and content that the platform does not model well. That changes the calculus considerably, and we cover related territory in our look at BigCommerce vs Shopify Plus for high SKU catalogs.
Schema Evolution Without Regret
Catalogs change constantly. New categories arrive with new attributes, a marketplace integration demands a new field, and a rebrand renames half your options.
In MongoDB, evolution is cheap at write time: add a field and start writing it. The cost is deferred, because old documents lack the field and queries must handle both shapes. Teams that thrive here version their documents with a schema version field and migrate in batches.
In Postgres, adding a nullable column is fast on modern versions, and adding an attribute inside JSONB needs no migration at all. Changing the type of a hot column is a real migration that needs planning on a large table. The reward is that the database tells you immediately when something is inconsistent, rather than letting the inconsistency spread silently.
The practical advice: keep the stable core in typed columns, put volatile attributes in JSONB, and validate both. That gives you most of the flexibility of documents with the safety of constraints.
Search and Indexing
Neither database should be your storefront search engine at scale. Faceted navigation, typo tolerance, synonyms, and ranking are specialized problems, and dedicated engines handle them better. We compare those options in Algolia vs Elasticsearch for ecommerce search infrastructure.
That said, each database has a useful native story. Postgres offers full text search with tsvector, trigram indexes for fuzzy matching, and the pgvector extension for embeddings, all in the same engine as your catalog. For a small to mid sized catalog, that can be enough, and it removes a synchronization problem entirely. MongoDB Atlas offers Atlas Search and Atlas Vector Search, which are tightly integrated with the document model, though they tie you to the managed Atlas platform rather than to the open source server alone.
Whichever database you pick, build a pipeline that pushes catalog changes to your search index and treat the database as the source of truth.
The Decision Framework
| Dimension | Postgres | MongoDB |
|---|---|---|
| Variant model | Rows with foreign keys and unique SKUs | Embedded array or separate collection |
| Flexible attributes | JSONB with GIN and expression indexes | Native subdocuments |
| Cross entity transactions | Default and simple | Supported, but design around them |
| Schema enforcement | Strong, with constraints | Optional JSON Schema validation |
| Reporting and joins | Standard SQL | Aggregation pipelines |
| Native search | Full text, trigram, pgvector | Atlas Search and Vector Search |
| Operational story | Many managed hosts, open source | Atlas is the strongest path |
| Best fit | Catalog plus orders and inventory | Content heavy, read heavy catalogs |
Choose Postgres when your catalog, inventory, and orders live together, when you need reporting across them, or when your team already knows SQL. It is also the safer default if you are unsure, because JSONB absorbs most of the flexibility you would have wanted from documents.
Choose MongoDB when your catalog is primarily a content store with extreme attribute variety, when reads vastly outnumber writes, when the product page is the main query, and when orders and inventory live in another system. It is also a good fit if your team is deeply fluent in the document model and you are committed to Atlas.
Choose both only with a clear boundary, such as MongoDB for enriched product content and Postgres for transactional state. Two databases double your operational surface.
What This Means for Your Business
Database choice shows up in your business as speed of merchandising, correctness of stock, and cost of change. A catalog that cannot absorb a new product category without an engineering sprint slows your merchandisers. An inventory system that oversells during a promotion costs you refunds and trust. Both failures are preventable with the right model, and the right model depends on which failure hurts you more.
For most commerce teams, we would weigh correctness above flexibility, because flexibility is cheap to add through JSONB and correctness is expensive to retrofit. If your platform already owns orders, weigh content flexibility and read performance more heavily instead. Our guide on AI product description generation at scale for headless catalogs shows how much a flexible, well structured attribute layer matters once you start enriching products automatically.
How Contra Collective Bridges the Gap
We design catalog and commerce data models for headless stacks, including the decision about what belongs in the platform, what belongs in your own database, and how it all syncs to search and storefronts. We will pressure test your variant model against your real merchandising workflow before you commit to a schema. If you are weighing Postgres, MongoDB, or a hybrid, talk to our team.
Final Thoughts
Postgres vs MongoDB is not a question of which database is better; it is a question of which parts of your catalog are flexible and which must never be wrong. Postgres with JSONB covers the widest range of commerce needs and makes cross entity correctness the easy path. MongoDB shines for content heavy, read heavy catalogs where the product document is the unit of work. Separate the descriptive, variant, transactional, and discovery layers, choose for the hardest one, and validate everything you let in.
More from the lab.
Bun vs Node.js: Runtime Decisions for Production Storefronts
Bun is fast, pleasant, and increasingly capable, but a production storefront runtime is a risk decision, not a speed contest. The smartest teams adopt Bun in layers, starting with tooling and moving to production only when the evidence supports it. Here is a practical way to decide.
Turborepo vs Nx: Monorepo Tooling for Storefront Teams
Turborepo and Nx both promise faster builds and saner monorepos, but they push you toward different working styles. For storefront teams sharing a design system across several brands, the choice shapes CI time and governance for years. Here is how to pick.
Commercetools vs. Shopify Plus: The Case for Pure Headless Commerce
When enterprise teams choose between commercetools and Shopify Plus, they're really choosing between two fundamentally different philosophies about ownership, flexibility, and velocity. Here's the unvarnished technical breakdown.