Skip to content

A Note Of Brewer's/CAP Theorem

Last Updated on 2024-11-27 by Clay

Recently, I have been reviewing notes on distributed systems to reflect on the systems I built over the past year and examine potential areas for improvement. Someone recommended studying the CAP theorem, and after reading it, I found it quite intuitive, so I decided to document it here.

The CAP theorem stands for:

  • Consistency (Consistency): All nodes always return the same data
  • Availability (Availability): Every request receives a response, though it may not reflect the latest data
  • Partition Tolerance (Partition Tolerance): The system continues to operate even when network partitions occur, where communication between nodes may fail to synchronize within a set timeframe

The CAP theorem states that in a distributed system, it is impossible to simultaneously achieve all three properties: Consistency, Availability, and Partition Tolerance. You can only achieve two at most.

CA Systems (Consistency + Availability)

Let’s start with CA systems.

It’s often said that we cannot sacrifice P, which leaves us to choose between CP and AP. This is because choosing a CA system implies there are no network partitions, which does not fully align with the characteristics of a distributed system.


CP Systems (Consistency + Partition Tolerance)

These systems prioritize consistency while tolerating partitions. In the event of errors causing data inconsistency across different nodes, the system will opt to return an error rather than providing stale or outdated data, thus maintaining consistency.

A classic example is a distributed database, where returning an error is preferred over delivering outdated data.


AP Systems (Availability + Partition Tolerance)

These systems prioritize availability at the expense of consistency. During network partitions, they allow the return of stale or outdated data but ensure the service remains operational.

A classic example is DNS.


Conclusion

The essence of the CAP theorem lies in determining the priority of system functionality since you must choose between consistency and availability.


References


Read More

Leave a Reply