From "Designing Data-Intensive Applications"
🎧 Listen to Summary
Free 10-min PreviewThe Document Model: Design, Benefits, and Challenges
Key Insight
Document databases, including examples like MongoDB, RethinkDB, and CouchDB, embrace a data model where information is stored as self-contained documents, often utilizing JSON for its simplicity compared to XML. This structure is highly appropriate for data exhibiting a tree of one-to-many relationships, where the entire document is typically retrieved and processed in a single operation, such as representing a LinkedIn profile with nested positions, education, and contact information, thereby avoiding the complexities of multi-table relational schemas.
A significant advantage of the document model is enhanced data locality; documents are commonly stored as single, continuous strings (e.g., JSON or BSON), which improves performance when applications frequently access substantial portions of a document. This locality minimizes the need for multiple index lookups and disk seeks that would be required if data were fragmented across various relational tables, and many developers find that the JSON model itself intrinsically reduces the impedance mismatch between application code and the storage layer.
Nevertheless, the document model faces challenges, particularly concerning many-to-many relationships and data consistency. Its support for joins is often weak or absent, forcing application developers to manually emulate joins through multiple database queries, which can lead to increased code complexity and slower performance compared to native database-level joins. Furthermore, documents are generally recommended to be kept small, as updates often involve rewriting the entire document, and as applications evolve and data becomes more interconnected, the document model may become less suitable, making relational or graph models more natural choices.
📚 Continue Your Learning Journey — No Payment Required
Access the complete Designing Data-Intensive Applications summary with audio narration, key takeaways, and actionable insights from Martin Kleppmann.