Document Schema Design
What are the key trade-offs of Document Schema Design? When would you choose it vs alternatives?
Answers use simple, clear English.
Audio N/AQuick interview answer
Pros: Flexible schema evolves without migrations; embed reduces joins. Cons: Unbounded arrays hit 16MB doc limit; duplicate data needs sync strategy.
Detailed answer
Pros: Flexible schema evolves without migrations; embed reduces joins. Cons: Unbounded arrays hit 16MB doc limit; duplicate data needs sync strategy. Decision: pick when benefits outweigh operational cost. Core: Embed when data accessed together and bounded size; reference when unbounded growth or shared entities. Balance read patterns vs write amplification. Real-time example: Order embeds line items array; Product referenced by id when catalog shared across orders. Pros: Flexible schema evolves without migrations; embed reduces joins. Cons: Unbounded arrays hit 16MB doc limit; duplicate data needs sync strategy. Common mistakes: Deep nesting mirroring relational 3NF; giant embedded arrays. Best practices: Design for queries; use schema validation; monitor document size. Audience level: Senior.
Full explanation
Embed when data accessed together and bounded size; reference when unbounded growth or shared entities. Balance read patterns vs write amplification.
Real example & use case
Order embeds line items array; Product referenced by id when catalog shared across orders.
Pros & cons
Pros: Flexible schema evolves without migrations; embed reduces joins. Cons: Unbounded arrays hit 16MB doc limit; duplicate data needs sync strategy.
Common mistakes
Deep nesting mirroring relational 3NF; giant embedded arrays.
Best practices
Design for queries; use schema validation; monitor document size.
Follow-up questions
- How would you test Document Schema Design?
- What metrics prove Document Schema Design is healthy in prod?
- How does Document Schema Design change at 10× traffic?