Ch. 2
Relational Model Versus Document Model
The relational and document models represent data differently — and each shines for different access patterns.
At the heart of every database is a data model: the abstraction it exposes to applications. For decades, the relational model dominated. The rise of web applications brought document databases back into focus, each arguing they better fit modern development.
The Object-Relational Mismatch
Object-oriented code thinks in nested structures; relational tables are flat rows. ORMs bridge this gap but introduce impedance mismatch — awkward joins, N+1 queries, and schema migrations that fight your object model.
- Relational: strong for ad-hoc queries, joins, and enforcing referential integrity.
- Document: strong for hierarchical data, flexible schemas, and horizontal scaling.
- Graph: strong when relationships are the primary query pattern (covered next).
relational modeldocument modelPostgreSQLMongoDBnormalizationimpedance mismatch