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
The same data as normalised tables and as nested documents, and what each shape makes easy.
The same data, both ways
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.
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.
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.
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.
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.
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.
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.
Answer without scrolling back up.
When does the document model genuinely beat normalised rows?
The data is contiguous and deserialises straight into an object. The gap widens as the object gains parts - and closes when queries come from other directions.
What is the real cost of copying a customer's address into every order document?
The question is whether the copies must agree. On an invoice the address arguably should be a historical fact, in which case it is not duplication at all.
Why has the relational/document distinction largely dissolved?
Tables for entities queried from several directions, a JSON column for genuinely variable parts read only alongside their parent - in one database, in one transaction.
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.