• Can not be achieved in the same time
    • Consistency
    • Availability
    • Partition tolerance

image.png

Partition Tolerance

the system continues to operate despite arbitrary message loss or failure of part of the system

Can not be avoided.

Consistency

All nodes see the same data at the same time
Consistency in CAP is a shortcut for Atomic Consistency.

  • 客户端

    • 从客户端来看,一致性主要指的是多并发访问时更新过的数据如何获取的问题。
  • 服务端

    • 从服务端来看,则是更新如何分布到整个系统,以保证数据最终一致。
  • 强一致性

    • 对于关系型数据库,要求更新过的数据能被后续的访问都能看到,这是强一致性。
  • 弱一致性

    • 如果能容忍后续的部分或者全部访问不到,则是弱一致性。
  • 最终一致性 (Eventual Consistency)

    • 如果经过一段时间后要求能访问到更新后的数据,则是最终一致性。
  • Sequential consistency, as defined by Lamport V9: “the program behaves as if the memory accesses of all processes were interleaved and then executed sequentially.”

  • Atomic Consistency (also called linearizability) is sequential plus a real-time constraint: “Unlike sequential consistency, linearizability implicitly assumes the notion of an observable global time across all processes. Operations are modeled by an interval which consists of the period of time between the invocation and response for the operation and each operation is assumed to take effect instantaneously at some point within this interval.” V7

Availability

In CAP, being available means all non-failing nodes continue to serve requests if the system is partitioned. Many distributed systems will consider themselves as available if, when there is a partition, some non-failing nodes continue to serve requests. These systems are not available-in-CAP.


  • CA without P:如果不要求 P(不允许分区),则 C(强一致性)和 A(可用性)是可以保证的。但其实分区不是你想不想的问题,而是始终会存在,因此 CA 的系统更多的是允许分区后各子系统依然保持 CA。
  • CP without A:如果不要求 A(可用),相当于每个请求都需要在 Server 之间强一致,而 P(分区)会导致同步时间无限延长,如此 CP 也是可以保证的。很多传统的数据库分布式事务都属于这种模式。
  • AP wihtout C:要高可用并允许分区,则需放弃一致性。一旦分区发生,节点之间可能会失去联系,为了高可用,每个节点只能用本地数据提供服务,而这样会导致全局数据的不一致性。现在众多的 NoSQL 都属于此类。
WordDatabasesCAPConfusion
TransactionA set of operations.The word and the concept are not used.No
Durable”Once a transaction completes successfully, its changes to the state survive failures.” [D2]The word and the concept are not used.No
ConsistentIntegrity constraints on the data (data types, relations, …)For CAP, Consistency is a shortcut for “Atomic Consistency”. The atomic consistency is a consistency model.Same word, different concepts
Isolation”Even though transactions execute concurrently, it appears to each Transaction, T, that others executed either before or after T.” [D2]The word is not used in CAP but the word Isolation as defined in ACID is a consistency model in CAP vocabulary.Different words but same concept
AtomicAll changes happen or none happen.For CAP, Atomic is a consistency model, the one used in the CAP proof.Same word, different concepts
AvailableConcept not often used. If so, the definition can be different than in CAP, i.e. available may not require all the non-failing nodes to respond.”Every request received by a non-failing node in the system must result in a response.” [C2]Same word, same concept, different definitions
PartitionConcept not often used. If so, the definition is the same as in CAP.Two sets of nodes are partitioned when all messages between them are lost.No
  • Consistency in CAP actually means linearizability, which is a very specific (and very strong) notion of consistency. In particular it has got nothing to do with the C in ACID, even though that C also stands for “consistency”. I explain the meaning of linearizability below.
  • Availability in CAP is defined as “every request received by a non-failing [database] node in the system must result in a [non-error] response”. It’s not sufficient for some node to be able to handle the request: any non-failing node needs to be able to handle it. Many so-called “highly available” (i.e. low downtime) systems actually do not meet this definition of availability.
  • Partition Tolerance (terribly mis-named) basically means that you’re communicating over an asynchronous network that may delay or drop messages. The internet and all our datacenters have this property, so you don’t really have any choice in this matter.