Struggling with the CAP theorem? Learn why you must choose between Consistency and Availability (CP vs AP), with real-world database examples like Cassandra and MongoDB.
The CAP theorem states that a distributed system can only guarantee two of the following three properties at the same time:
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 — use when correctness is critical: bank transfers, inventory, leader election.
AP — use when availability matters more: social feeds, shopping carts, product catalogs.
| Database | Type | Reasoning |
|---|---|---|
| PostgreSQL | CP | Synchronous replication — consistency first |
| MongoDB | CP (default) | Primary-only reads by default |
| Cassandra | AP | Tunable consistency, defaults to availability |
| DynamoDB | AP (default) | Eventually consistent reads by default |
| Redis | CP | Single primary, replicas are async |
| Zookeeper | CP | Designed for coordination |
| CouchDB | AP | Designed for offline-first |
CAP only covers partition behavior. PACELC extends it to normal operation: