Skip to main content
CAP
  1. Posts/

CAP

·296 words·2 mins·
Roman
Author
Roman
Photographer with MSci in Computer Science and a Home Lab obsession
Table of Contents
CAP Theorem A.K.A Brewer’s Theorem is a principle in distributed systems that states that it is impossible for a distributed system to simultaneously provide all 3 guarantees

Consistency
#

Ensures all nodes in the distributed system have the same data at the same time. Change in one node should also be reflected in all nodes.

  • Strong Consistency: All read and writes operations are guaranteed to be immediately consistent with each other, regardless of network delays or failures

Availability
#

System is always operational and responsive to requests regardless of partial node failure

  • High Availability: The system remains operational and responds to requests even in presence of network or other system issues.

Partition Tolerance
#

Systems ability to continue functioning even if a network partition occur

  • Partition Tolerance: The system continues to operate, even when network communications between nodes is unreliable or fails.

Trade-offs
#

Can only achieve 2 out of those properties at the same time

CA
#

Prioritises both consistency and availability. They do not tolerate network partitions an always aim for strong consistency.

  • RDBMS, PostgreSQL running on a single node

AP
#

Prioritise availability and partitioning tolerance over strict consistency. The systems may provide eventual consistency, where data may take some time to propagate and become consistent across all nodes.

  • Cassandra, DynamoDB

CP
#

Consistency is prioritised, even at the expense of availability. When network partition occurs, the system might choose to become temporary unavailable rather than risk delivering inconsistent data

  • MongoDB, HBase, Redis

Not about finding the perfect solution, it’s about finding the best solution for our specific use case

it’s not black and white, just because not all parts of the system have to be either CP or AP for example, can be a mix and match on different fields and data