Course contentsShow
← System Design
Lesson 381 of 1,91911. NoSQL: Document StoresFree lesson

Documents vs Rows in Relational Databases

Documents encapsulate related data in one place, avoiding joins, while relational rows require normalized tables.

Documents vs Rows in Relational Databases

What you'll learn: How documents in NoSQL stores differ fundamentally from rows in relational tables, especially regarding data relationships and joins.

The Core Difference

In a relational database, data is split across normalized tables with rows connected through foreign keys. To retrieve complete information (like a blog post with its comments), you must perform JOIN operations across multiple tables.

In a document store, related data is encapsulated together in a single JSON-like document. Everything you need is in one place—no joins required.

The Row Approach (Relational)

Imagine organizing a user's profile across separate filing cabinets:

  • Cabinet 1: User basic info
  • Cabinet 2: User addresses
  • Cabinet 3: User phone numbers

To get the complete picture, you visit all three cabinets and assemble the pieces (that's a JOIN).

Users Table:        Addresses Table:
+------+-------+    +------+-------------+
| id   | name  |    | user | street      |
+------+-------+    +------+-------------+
| 101  | Alice |    | 101  | 123 Main St |
+------+-------+    +------+-------------+

Query requires: SELECT * FROM Users JOIN Addresses...

The Document Approach

A document stores the entire user in one object:

{
  "id": 101,
  "name": "Alice",
  "addresses": [
    {"street": "123 Main St", "city": "Boston"}
  ],
  "phones": ["555-1234"]
}

One read operation retrieves everything. No joins, no multiple table lookups.

Why This Matters

Documents align with how applications think about entities—whole objects, not scattered fragments. This makes reads faster (no join overhead) and code simpler. However, updating shared data (like changing a city name used by millions of users) becomes harder since it might exist in many documents.

Key Takeaway: Documents bundle related data into self-contained units for fast retrieval without joins, while relational rows distribute data across normalized tables requiring joins to reconstruct complete entities.