Back to 20 Concepts
availability • Advanced
CAP Theorem & PACELC Tradeoffs in Distributed Databases
The CAP Theorem states that in the presence of a Network Partition (P), a distributed system must choose between Consistency (C) or Availability (A). PACELC extends this to normal operating conditions (Latency vs Consistency).
Intuitive Mental Model
The Bank Branch Phone Line Cut: If the phone line between the New York and London bank branches is severed (Partition), the bank can either reject transactions to guarantee identical balances (CP), or allow both branches to accept deposits independently and sync later (AP).
Architecture Blueprint & CodeProduction Standard
// PACELC Mapping: // 1. DynamoDB / Cassandra: PA/EL (High availability on partition, Low latency normally) // 2. MongoDB / HBase: PC/EC (Strong consistency always, rejects writes on partition) // 3. Spanner / Cockroach: PC/EC with TrueTime Atomic Clocks
Key Architectural Takeaways
- •Partitions Are Inevitable: In real-world networks (cables cut, switch failure), P is non-negotiable; architects can only choose between C and A.
- •Linearizability (CP): Every read returns the most recent write, but requests fail if a partition isolates a replica.
- •Eventual Consistency (AP): All reads return immediately, but replicas may serve stale data until convergence.
Common Architectural Pitfall
Claiming a system is "CA" (Consistent and Available); network partitions are a physical reality of distributed infrastructure.
Production Best Practice
Design distributed architectures acknowledging network partitions and choosing CP or AP deliberately.