ACID and CAP
RDBMS: relational databases (Mysql/Oracle/SqlServer) follow ACID
A (Atomicity
C (Consistency) Consistency
I (Isolation) Independence
D (Durability)
-
A (Atomicity) :
Atomicity is easy to understand, which means that all operations in a transaction are either done or not done at all. The condition for the success of a transaction is that all operations in a transaction are successful. As long as there is one failure, the whole transaction fails and needs to be rolled back. For example, A bank transfer, transferring 100 yuan from account A to account B, is A two-step process.
- I’m going to take $100 from account A
- Deposit $100 into account B
These two either complete together, or do not complete together, if only complete the first step, the second step failed, the money will be puzzling less 100 yuan.
-
C (Consistency) :
The database is always in a consistent state, and the execution of a transaction does not change the consistency constraints of the database
-
I (Isolation) :
Independence means that concurrent transactions do not affect each other. If a transaction is accessing data that is being modified by another transaction, the data it accesses is not affected by the uncommitted transaction as long as the other transaction is not committed. For example, transfer 100 yuan from account A to account B, under the condition that the transaction is not completed, if B queries his own account at this time, he will not see the newly added 100 yuan
-
D (Durability) :
Persistence means that once a transaction is committed, its changes will be permanently stored in the database and will not be lost in the event of an outage.
NOSQL :(Redis/Mongdb) follows CAP
C (Consistency) Strong Consistency
A Availability
P (Partition tolerance) Fault tolerance of a Partition
The core of CAP theory is that it is impossible for a distributed system to meet the three requirements of consistency, availability and fault tolerance of partition at the same time. Therefore, according to CAP principle, NoSql database is divided into three categories that meet CA principle, CP principle and AP principle:
-
CA (mostly used in traditional MySql, Oracle and other databases)
A single point cluster, a system that satisfies consistency and availability, is usually not very strong in scalability.
-
CP (mostly used in Redis, Mongodb, etc.)
Systems that meet consistency and fault tolerance of partitions usually do not perform particularly well.
-
AP (Choice of most Website architectures)
Systems that meet availability and fault tolerance of partitions may generally have lower requirements for consistency. (For example, the number of likes for a certain product on an e-commerce website, whether it is 110,000 or 120,000, is not a high requirement for consistency)
Classic CAP figure
CAP goes 3 into 2
CAP theory says that in a distributed storage system, only two of the above can be implemented.
And because the current network hardware will certainly appear delay packet loss and other problems, so
Partition fault tolerance is something we must implement.
So there is a trade-off between consistency and availability, and no NoSql system can guarantee all three.