Where should a catalog go when every product type has different attributes?
Applications like this: shops with shoes, laptops and food in one catalog. Real estate listings. Car parts. This page is written the way I write a database design doc: the workload first, then where each kind of data goes and why, then how it grows, what breaks, and what I rejected.
| Dimension | This application |
|---|---|
| Writes | Low. Merchants edit products a few times a day. |
| Reads | Very high. Every page view, every search, every filter. |
| Read to write | Hundreds to one, or more. |
| Consistency | Loose. A price change can take a second to appear in search. |
| Latency | Product pages from cache in milliseconds. Search under 200 ms. |
| Growth | Moderate. Thousands to millions of products. |
These incidents are why the choices below matter. Each one is written up with its numbers and sources.
Solid arrows: the application writes there. Dashed arrows: a copy fed from the source of truth (change data capture, an outbox, or a cache fill), which can be rebuilt from it.
| Data | Where it goes | Why |
|---|---|---|
| The product of record | PostgreSQL with JSONB, or MongoDB | Shared fields (price, title, stock link) as columns or fields. Type-specific fields in JSONB or the document. |
| Browsing, filters, facets, full-text | Elasticsearch or OpenSearch | Counting matches per color, size and brand across millions of products is what an inverted index is for. |
| Product pages | A cache or a CDN | Pages change rarely and are read constantly. |
How each family of store behaves under traffic: Database families.
CREATE TABLE products (
id bigint PRIMARY KEY,
sku text UNIQUE NOT NULL,
title text NOT NULL,
price_cents bigint NOT NULL,
category text NOT NULL,
attrs jsonb NOT NULL DEFAULT '{}' -- {"ram_gb":16, "color":"black"}
);
CREATE INDEX ON products USING gin (attrs jsonb_path_ops);
SELECT id, title FROM products
WHERE category = 'laptops' AND attrs @> '{"ram_gb": 16}';
Pick a stage, then throw something at it. The numbers are a model to show the shape of each change, not a measurement; the measured numbers are in the lab notebooks.
| What happens | What you see | What I do |
|---|---|---|
| LIKE %term% on titles | Sequential scans in the slow log | Move text search to a search engine, or use full-text search in PostgreSQL for small catalogs. |
| The search index out of sync | A product shows a price it no longer has | Write changes to an outbox table in the same transaction, and have one process ship them to the index. |
| Every attribute in JSONB | Joins and sorts on JSON fields are slow and hard to index | Promote frequently used attributes to columns. |
Cost. Search clusters are often the largest line on a catalog bill. Size them for the index you have, and keep replicas at what the query rate needs.
| Stage | Where it runs |
|---|---|
| Where I would start | Managed relational, plus a managed search service |
| When it grows | The same, with a CDN in front |
For a team without a dedicated database team. Who does which job in each option, and the full-cost comparison: Where to run the database.
The back-of-the-envelope numbers I would want before choosing anything. Move the assumptions to match your application. The link keeps your numbers, so a colleague sees the same ones.
Which database does my application need? What kind of application data goes in which database, and why, as design docs, plus the anti-patterns and the decisions behind them.