Skip to content

Designing Data-Intensive Applications - 2. Data Models and Query Languages

Published: at 10:25 AM

Table Of Contents

Open Table Of Contents

Driving Forces Behind NoSQL Databases

NoSQL databases emerged due to several key motivations:

Relational vs. Document Databases

Relational Model Characteristics

Some relational databases

Document Model Characteristics

Some document databases

The Object-Relational Impedance Mismatch

A key criticism of relational databases is the translation layer required between:

Representing Complex Data Structures

Handling One-to-Many Relationships

Relational databases manage these through:

  1. Separate tables with foreign key references
  2. Structured datatypes (XML, JSON)
  3. Encoded documents within text columns

Example: LinkedIn Profile Representation

Relational Approach: Multiple normalized tables

Document Approach: Single JSON document with embedded data

{
    "user_id": 251,
    "first_name": "Bill",
    "last_name": "Gates",
    "positions": [
        {"job_title": "Co-chair", "organization": "Bill & Melinda Gates Foundation"},
        {"job_title": "Co-founder, Chairman", "organization": "Microsoft"}
    ],
    "education": [
        {"school_name": "Harvard University", "start": 1973, "end": 1975},
        {"school_name": "Lakeside School, Seattle"}
    ]
}

Schema Approaches

Schema-on-Write (Relational)

Schema-on-Read (Document)

When to Choose Relational Databases

  1. Complex Relationships and Joins
  2. Strong Data Integrity and Consistency
  3. ACID Transactions
  4. Many-to-one/Many-to-many relationships (If you have many many-to-many relationships, you may also consider graph databases)

When to Choose Document Databases

  1. Schema changes frequently
  2. Entire document needs to be accessed in a single read
  3. Data has a document-like structure (tree of one-to-many relationships)

Query Languages

SQL Advantages

Alternative Query Approaches

Graph Data Model

Particularly suitable for:

Practical Considerations

Performance Limitations

Future of Data Models

A hybrid approach is emerging, with:


Contribute to this article here.