Vivcre Learn learn it · write it · retain it

← All posts

Database #mongodb#data-modeling#embedding#references#schema-design

MongoDB Data Modeling: Start From the Workload

25 Jun 2026

There’s one idea under the whole document-modeling story, and everything else — embedding, references, anti-patterns, schema validation — is downstream of it.

The inversion

In the relational world you model data to be correct in the abstract: normalize, put one fact in one place, and let queries bend to fit the schema. The schema is optimized for no particular workload. MongoDB flips this. You start from the workload — which queries run, how often — and shape the data so that whatever is read together is stored together. That single move is why a good MongoDB modeling exercise spends its first real effort just counting operations before anyone touches a schema: the workload silently decides every later choice.

Embed vs reference is a tradeoff you already know

The central decision — embed or reference — is the same read/write tradeoff from storage engines (B-tree vs LSM), lifted to the schema layer.

Same read-vs-write instinct, new target. You’re not learning a new reflex; you’re aiming one you already own at documents instead of pages.

The anti-pattern: embedding an unbounded array

Take a book with reviews. The obvious read-optimized move is to embed the reviews so one query fetches everything. But a popular book’s reviews grow without bound — they only accumulate. MongoDB reads and writes whole documents, so:

Embedding a collection that grows without bound is the unbounded-array anti-pattern. The fix is to reference: reviews live in their own collection, each pointing at the book by id. The “many” side owns the data, and you accept a read-time lookup in exchange for bounded, cheap documents.

Where this goes next

The full framework is a cardinality ladder — one-to-few (embed), one-to-many (reference, sometimes with a small embedded subset), one-to-zillions (always reference) — plus a guideline table for the edge cases. But the load-bearing move is the one above: count the workload first, then let embed-vs-reference fall out of it.


Practise these questions →

Spaced-repetition MCQs for this post, on practise.vivcre.com.