MongoDB
CAP Theorem: Consistency, Availability, and Partition Tolerance
Master the CAP theorem and learn how it guides architectural decisions in distributed databases like MongoDB, Cassandra, and HBase.
S
srikanthtelkalapally888@gmail.com
CAP Theorem
CAP Theorem states that a distributed system can only guarantee two of three properties simultaneously.
The Three Properties
Consistency (C)
Every read receives the most recent write or an error.
Availability (A)
Every request receives a response (not necessarily the latest data).
Partition Tolerance (P)
The system continues to operate despite network partitions.
CAP Trade-offs
CP Systems → Sacrifice Availability
Examples: HBase, MongoDB (strong mode), Zookeeper
AP Systems → Sacrifice Consistency
Examples: Cassandra, CouchDB, DynamoDB
CA Systems → Not realistic in distributed systems
(Can't avoid network partitions)
Practical Implications
| System | Choice | Use Case |
|---|---|---|
| Cassandra | AP | High availability writes |
| HBase | CP | Strong consistency needed |
| DynamoDB | AP (default) | Eventually consistent |
PACELC Extension
PACELC extends CAP by also considering Latency vs Consistency tradeoffs during normal operation.
Conclusion
Understanding CAP helps engineers choose the right database for their consistency and availability requirements.