Our understanding of CAP theorem has changed considerebly since its first appearance in 2000. There were a lot of confusion about the "chose-2-out-of-3" concept but Eric Brewer's article in 2012 nicely eliminated these confusions (I guess).
So, CAP theorem is not about being CA or AP or something else. It is simply this: Network partitions may happen all the time. It is unavoidable. And when a network partition happens, the architecture of a distributed database should allow its clients to tune consistency and availability as they wish.
What does this mean? Assume that you replicate a piece of data between 3 nodes (N1, N2, and N3 - so replication factor = 3) in a cluster. And let's say that a network partition happens which seperates N3 from N1 and N2:
So, all of the 3 nodes are operational, but the network between them is problematic right now. In this situation a client might make a read request or a write request to N1, N2 or N3. Based on the consistency choices of this client, the reaction of the cluster may differ:
- If the client makes a read request to N1, N1 can answer the query right away with its own data. Or N1 can forward the same query to N2 and compares its data with N2's data and returns the most up-to-date one. Here, the reaction of the cluster depends on the consistency choice of the client. Client tunes consistency according to its choices.
- Client can make a different choice too: It can force N1 to read data from all 3 nodes (i.e. read consistency of ALL in Cassandra terms). In this situation, cluster returns an error and we say that the cluster is not available accodring to the client's choice.
- Another possibility might be this one: Client might have asked the data to N3. In this situation, N3 only returns its data (read consistency = ONE) or the query fails (read consistency > 1).
I don't know about Mongo but this is how Cassandra works considering the CAP theorem.
Answer from burak ibrahim sevindi on Stack OverflowOur understanding of CAP theorem has changed considerebly since its first appearance in 2000. There were a lot of confusion about the "chose-2-out-of-3" concept but Eric Brewer's article in 2012 nicely eliminated these confusions (I guess).
So, CAP theorem is not about being CA or AP or something else. It is simply this: Network partitions may happen all the time. It is unavoidable. And when a network partition happens, the architecture of a distributed database should allow its clients to tune consistency and availability as they wish.
What does this mean? Assume that you replicate a piece of data between 3 nodes (N1, N2, and N3 - so replication factor = 3) in a cluster. And let's say that a network partition happens which seperates N3 from N1 and N2:
So, all of the 3 nodes are operational, but the network between them is problematic right now. In this situation a client might make a read request or a write request to N1, N2 or N3. Based on the consistency choices of this client, the reaction of the cluster may differ:
- If the client makes a read request to N1, N1 can answer the query right away with its own data. Or N1 can forward the same query to N2 and compares its data with N2's data and returns the most up-to-date one. Here, the reaction of the cluster depends on the consistency choice of the client. Client tunes consistency according to its choices.
- Client can make a different choice too: It can force N1 to read data from all 3 nodes (i.e. read consistency of ALL in Cassandra terms). In this situation, cluster returns an error and we say that the cluster is not available accodring to the client's choice.
- Another possibility might be this one: Client might have asked the data to N3. In this situation, N3 only returns its data (read consistency = ONE) or the query fails (read consistency > 1).
I don't know about Mongo but this is how Cassandra works considering the CAP theorem.
Cassandra uses tunable consistency, that you can control it when writing and/or reading data by using different consistency levels. For example, if you use QUORUM for both writes & reads, then you get strong consistency, although availability may suffer.
P.S. I can't say about Mongo though...