Embedding vs Referencing Documents in MongoDB
Fast recall
Quick revision
Core answer
findOne returns the whole aggregate atomically. Reference when data is shared across many parents, grows unboundedly, is independently queried, or would push the parent past the 16MB document limit. The canonical rule is: 1:few embed, 1:many consider, 1:squillions always reference. A common hybrid is the extended reference pattern — embed a denormalized subset of the child (id + name + a couple of fields) while keeping the full child in its own collection — fast reads without the full duplication tax.Schema modeling instinct driven by access patterns rather than relational normalization habits
Embedding unbounded arrays that hit 16MB, or over-referencing when data is always read together
Name the extended reference pattern, cite MongoDB's 1:few / 1:many / 1:squillions guidance, and show a concrete embedded vs referenced JSON pair
Interview-ready guide
Interview answer
State the rule
- Embed when you can, reference when you must
- 1:few embed, 1:many consider, 1:squillions always reference
Describe the triggers for referencing
- Unbounded growth
- Shared ownership
- Independent querying
- 16MB document cap
Offer the hybrid
- Extended reference — embed a denormalized subset of the child while keeping the source of truth in its own collection
- Fan out updates via change streams when the source changes
Close
- Always design for access patterns
- Don't rebuild SQL joins in application code; if they dominate, reconsider MongoDB
Embedding vs Referencing Documents in MongoDB
Direct Answer
Embed when related data is read together, has 1:1 or 1:few cardinality, stays bounded in size, and is owned by one parent — one findOne returns the whole aggregate atomically. Reference when data is shared across many parents, grows unboundedly, is independently queried, or would push the parent past the 16MB document limit. The canonical rule is: 1:few embed, 1:many consider, 1:squillions always reference. A common hybrid is the extended reference pattern — embed a denormalized subset of the child (id + name + a couple of fields) while keeping the full child in its own collection — fast reads without the full duplication tax.
Common Mistakes & Pitfalls
Embedding unbounded arrays that hit 16MB, or over-referencing when data is always read together
Check your understanding
Answer these without looking back at the article.
- What is the extended reference pattern and when would you use it?
- How does the 16MB BSON document size limit influence your embedding decisions?
- How would you model a many-to-many relationship in MongoDB?
- When does `$lookup` become a performance problem and how do you mitigate it?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.