From Francesco Marchioni book “MongoDB for Java Developers”
when we talk about NoSQL databases, or,generally, if we are designing distributed systems, we might have to look beyond the
traditional ACID properties. As stated by the CAP theorem, coined by Eric Brewer,the following set of requirements are truly essential when designing applications for distributed architectures:
• Consistency: This means the database mostly remains adherent to its rules
(constraints, triggers, and so on) after the execution of each
operation and that any future transaction will see the effects of the
earlier transactions committed. For example, after executing an
update, all the clients see the same data.
• Availability: Each operation is guaranteed a response—a successful or
failed execution. This, in practice, means no downtime.
• Partition tolerance: This means the system continues to function even if
the communication among the servers is temporarily unreliable (for
example, the servers involved in the transaction may be partitioned
into multiple groups,which cannot communicate with one another).
In practice, as it is theoretically impossible to have all three
requirements met, a combination of two must be chosen and this is
usually the deciding factor in what technology is used, as shown in
the following figure:
If you are designing a typical web application that uses a SQL database, most likely, you are in the CA part of the diagram. This is because a traditional RDBMS is typically transaction-based (C) and it can be highly available (A). However, it cannot be Partition Tolerance (P) because SQL databases tend to run on single nodes. MongoDB, on the other hand, is consistent by default (C). This means if you perform a write on the database followed by a read, you will be able to read the same data (assuming that the write was successful). Besides consistency, MongoDB leverages Partition Tolerance (P) by means of replica sets. In a replica set, there exists a single primary node that accepts writes, and asynchronously replicates a log of its operations to other secondary databases.
However, not all NoSQL databases are built with the same focus. An example of
this is CouchDB. Just like MongoDB, it is document oriented and has been built to scale across multiple nodes easily; on the other hand, while MongoDB (CP) favors consistency, CouchDB favors availability (AP) in spite of consistency. CouchDB uses
a replication model called Eventual Consistency. In this model, clients can write data to one database node without waiting for acknowledgment from other nodes.The system takes care to copy document changes between nodes, so that
