Course contentsShow
← Computer Science
Lesson 2608 of 2,87258. Distributed Systems BasicsFree lesson

CAP Theorem in Practice: Database Examples

Analyzing how real databases like MongoDB, Cassandra, and traditional RDBMS make CAP trade-offs.

CAP Theorem in Practice: Database Examples

You'll learn: How real-world databases like MongoDB, Cassandra, and traditional RDBMS actually navigate the CAP trade-offs in their architectures.

From Theory to Practice

The CAP theorem isn't just academic—every distributed database makes deliberate choices about consistency, availability, and partition tolerance. Let's examine how popular databases position themselves.

MongoDB: CP-Leaning with Tunable Consistency

MongoDB traditionally favors consistency and partition tolerance. When a network partition occurs, MongoDB's replica sets elect a new primary only when majority consensus exists. If a minority node is isolated, it stops accepting writes to prevent stale data. However, MongoDB lets you tune read preferences—you can request eventual consistency by reading from secondaries, gaining some availability at consistency's expense.

Analogy: Like a bank that freezes transactions during network issues rather than risk incorrect balances.

Apache Cassandra: AP-Focused

Cassandra chooses availability and partition tolerance. Every node can accept writes even during partitions, using eventual consistency to reconcile conflicts later (last-write-wins by timestamp). You can tune consistency per operation using quorum levels, but its default stance prioritizes staying responsive over immediate consistency.

Analogy: Like a distributed note-taking app where all copies stay writable, syncing changes when reconnected.

Traditional RDBMS (Single-Node): CA Systems

Classic relational databases like PostgreSQL or MySQL on a single server offer consistency and availability in non-distributed scenarios. They guarantee ACID transactions and stay available—but can't tolerate partitions because there's nothing to partition. Clustered versions shift toward CP or AP depending on configuration.

The Real Nuance

Modern databases blur these lines with tunable consistency levels, allowing developers to choose different guarantees per operation based on business needs.

Key Takeaway: MongoDB leans CP (consistency over availability during partitions), Cassandra favors AP (availability with eventual consistency), and traditional single-node RDBMS are CA (not partition-tolerant)—but most production systems offer configurable trade-offs rather than absolute positions.