Chapter 24: Why NoSQL? CAP Theorem and Trade-offs

NoSQL databases exist because relational databases have limitations at extreme scale. Understanding when (and when NOT) to use NoSQL is critical.

The CAP Theorem

In a distributed system, you can only guarantee two of three:

Consistency /\ / \ / \ / CA \ CP /________\ Availability — Partition Tolerance CA: Single-node RDBMS (PostgreSQL standalone) CP: Consistent distributed (MongoDB, HBase) — may reject requests during partition AP: Available distributed (Cassandra, DynamoDB) — may return stale data during partition In practice: network partitions WILL happen, so you choose between C and A.

When Relational Databases Struggle

When to Stay Relational

⚠️ The Most Common Mistake

Choosing NoSQL because it's "modern" or "scalable" when your data is clearly relational and fits on one PostgreSQL instance. A single PostgreSQL server handles millions of rows and thousands of queries/second. You probably don't need NoSQL.

BASE vs ACID

ACID (Relational)BASE (NoSQL)
AtomicBasically Available
ConsistentSoft state
IsolatedEventually consistent
Durable

BASE means: the system is always available, data may be temporarily inconsistent, but will converge to consistency eventually.

Key Takeaways