TechBlog
system-design

CAP Theorem Explained

The CAP theorem is one of the most important concepts in distributed systems. Understand what it means, what the trade-offs are, and how real databases make the choice.

3 min read

What is the CAP Theorem?

The CAP theorem states that a distributed system can only guarantee two of the following three properties at the same time:


Why You Can Only Pick Two

Network partitions are inevitable in distributed systems. The real choice is between Consistency and Availability when a partition occurs.

During a partition, you must choose:


CP vs AP Systems

CP — use when correctness is critical: bank transfers, inventory, leader election.

AP — use when availability matters more: social feeds, shopping carts, product catalogs.


Real Database Choices

DatabaseTypeReasoning
PostgreSQLCPSynchronous replication — consistency first
MongoDBCP (default)Primary-only reads by default
CassandraAPTunable consistency, defaults to availability
DynamoDBAP (default)Eventually consistent reads by default
RedisCPSingle primary, replicas are async
ZookeeperCPDesigned for coordination
CouchDBAPDesigned for offline-first

PACELC — The Full Picture

CAP only covers partition behavior. PACELC extends it to normal operation:


Key Takeaway

  1. Partition tolerance is mandatory — the real choice is C vs A
  2. CP → errors over stale data (banks, inventory)
  3. AP → stale data over errors (social feeds, carts)
  4. Most modern databases let you tune per operation