Concepts/3. Data & Storage/CAP Theorem (Consistency vs Availability)
🔺
3. Data & StorageIntermediate

CAP Theorem (Consistency vs Availability)

← All 150+ Concepts

In any distributed data store, network partitions (P) are inevitable. When a partition occurs, the system must choose between Consistency (CP) or Availability (AP).

STAFF ENGINEER TAKEAWAY: You cannot choose CA in distributed systems because network cables and routers will inevitably fail.
🔄

Partition Decision Matrix

1
Network Partition Event
Switch failure cuts Region A & B connection
✓
2
CP System Path
Rejects writes to prevent split-brain state
✓
3
AP System Path
Accepts writes locally; syncs via CRDTs later
✓
✓ ARCHITECTURAL ADVANTAGES

Provides an unambiguous framework for distributed tradeoffs.

✗ TRADE-OFFS & COMPLEXITIES

Forces architects to accept either downtime errors (CP) or stale reads (AP) during netsplit.

🏢

Production Systems Leveraging This Pattern

⚡CP: Spanner, ZooKeeper, etcd⚡AP: Cassandra, DynamoDB, CouchDB
Simulate in Visual Canvas→Read 30-Chapter Curriculum→

More Topics in 3. Data & Storage

🗄️SQL Relational vs NoSQL Engines

SQL databases enforce structured schemas and ACID transactions with relations. NoSQL systems optimize for flexible schemas, horizontal partition scale, and eventual consistency.

🌲B-Tree & B+Tree Indexing

Self-balancing search tree data structure that keeps data sorted and allows searches, sequential access, insertions, and deletions in logarithmic O(log N) time.

🏛️ACID Transactions & Isolation Levels

Guarantees Atomicity (all-or-nothing), Consistency (rules preserved), Isolation (concurrent safety), and Durability (WAL commits survive power loss).

👯Database Replication (Leader-Follower)

A primary leader node accepts all write transactions and streams change logs to secondary read replicas to scale read QPS and enable high availability.