Sobes.tech
Middle

What is the CAP theorem?

sobes.tech AI

Answer from AI

The CAP theorem (also known as Brewer's theorem) states that in a distributed computing system, it is impossible to simultaneously provide:

  • Consistency: All nodes see the same data at the same time. Any read operation gets the most recently written data.
  • Availability: Every request receives a non-empty response, regardless of the state of other nodes. The system is always available for read and write operations.
  • Partition Tolerance: The system continues to operate despite loss of communication between nodes (network partitions).

Under network partition ($P$), the system must choose between consistency ($C$) and availability ($A$).

  • CA system: Assumes no network partitions. When they occur, the system becomes either unavailable or inconsistent. Examples: classic relational databases with synchronous replication within a local network.
  • CP system: Sacrifices availability in favor of consistency during network partition. If a node cannot contact the majority, it stops responding to requests to guarantee data consistency. Examples: Zookeeper, etcd, distributed systems using consensus protocols like Paxos or Raft.
  • AP system: Sacrifices consistency in favor of availability during network partition. The system continues to respond to requests but may provide stale or conflicting data. Consistency is achieved later (eventual consistency). Examples: DynamoDB, Cassandra, MongoDB (by default in some configurations).

The CAP theorem applies to distributed data storage systems. In real systems, compromises are often necessary, and the most suitable model depends on the specific requirements of the application.

What is the CAP theorem? — Java - sobes.tech