liveBook · Manning

Denormalization

As explained in MongoDB 8.0 in Action, Third Edition

A denormalized data model stores related data together or redundantly to reduce the need for joins, separate queries, or cross-record operations.

Denormalization stores related data together, often by embedding it in one MongoDB document. This can reduce queries for routine operations and let related data be read or updated in a single operation. section 5.2

Consider embedding when:

  • One entity contains another, or child records are usually accessed with their parent. section 5.2
  • Related information is frequently accessed independently, duplication is not worthwhile, or the relationship is complex and many-to-many, consider separate documents and references instead. section 5.2
  • Avoid bloated documents: embedded data may be unused together and documents must remain below MongoDB’s 16 MB BSON limit. section 5.2
  • Treat denormalization as a schema-design choice, not a replacement for every join or distributed transaction; joins can be resource-intensive, and distributed transactions can cost more than single-document writes. section 8.4.3 section 6.2.2
Figure 5.1 A MongoDB document with embedded subdocuments for contact information and access details (Image © MongoDB 2024 CC BY-NC-SA 3.0)
A computer code on a black background

Description automatically generated

A contact document embeds address and access details as subdocuments. section 5.2

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains embedding and referencing choices, their performance trade-offs, and the BSON document-size limit.
Examples
Uses a contact document with embedded address and access details, and child records accessed in a parent’s context.
What you can do after
Evaluate whether to embed related data or reference separate documents based on access patterns, duplication, and relationship complexity.
How it connects
Connects embedding with document modeling, and denormalization with normalized schemas, joins, and distributed transactions.

Also explained in

Compare how 6 books explain denormalization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.