The Document Model against Rows

The same data as normalised tables and as nested documents, and what each shape makes easy.

The Document Model against Rows

The same data, both ways

query.sql SQLite
Result

Worth knowing

A document stores related data together, nested. A relational schema stores it apart and joins on demand.
Documents win when the access pattern is 'give me this whole thing' — one read, no joins.
Rows win when the data is queried from several directions, or when the same fact appears in many documents and has to stay consistent.
SQLite, PostgreSQL and MySQL all have JSON columns, so the choice is per-column now rather than per-database.

Overview

A document might store an order and its line items together. A relational design might put the order in one table and each line item in another, connected by an order key. Both can represent the same information. The practical choice is how the application reads, changes, and validates that information.

In this guide
  1. Two ways to shape related data
  2. Model around the work
  3. A storage change has consequences
  4. Example: orders and line items
  5. Keep repeated snapshots intentional
  6. Further reading

Embedding often makes a common read simple and keeps related data together. But duplicated or rapidly growing nested data can make updates harder. Referencing a separate document or relational row avoids some duplication but requires another lookup or join. MongoDB's guidance similarly frames embedding and references around access patterns and data relationships.

Model around the work

Ask which data is usually fetched together, which parts change independently, whether children can grow without bound, and what consistency is required across updates. If many workflows need different slices of the same entity, a single large embedded document may be awkward. If a small related object is always read with its parent, embedding may be simpler.

Relational schemas support constraints and flexible joins across tables. Document systems can provide schemas and transactions too, but details and limits depend on the product. “Schema-less” does not mean the application has no data contract.

A storage change has consequences

Changing storage shape affects indexes, validation, update semantics, and application code. Measure representative queries and define how existing documents or rows will be migrated. See relational databases and non-relational databases.

Example: orders and line items

An order document with a small, bounded list of line items can serve a page that always loads the whole order. If the same product details must stay consistent across thousands of orders, copying them into each document creates many values to update. A reference to a product record avoids that duplication but adds a read and may show current product details rather than the historical price. Historical order lines usually need their purchase-time price stored as part of the order. Model each field according to its meaning over time.

Keep repeated snapshots intentional

Some values should be copied because they describe a past event rather than the current source record. An order should usually preserve the item name and price charged at purchase time even if the product catalog later changes. That is different from accidentally duplicating a current address everywhere. Label snapshot fields clearly and decide which fields are historical facts versus live references. The same distinction applies in relational schemas and document stores; storage model alone does not solve temporal meaning.

Further reading

Check yourself

0 of 3

Answer without scrolling back up.

  1. When does the document model genuinely beat normalised rows?

  2. What is the real cost of copying a customer's address into every order document?

  3. Why has the relational/document distinction largely dissolved?

Cheat sheet

The Document Model against Rows

Store the same order as a nested document and as normalised rows, then run the queries each shape handles well and the ones it does not.

DATABASE · vizlearn.in/database/document_model_vs_rows.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.

Teaching a course with this? Individual teachers can use it freely; for a whole department or programme, see institutional licences.