CAP, acid for in-depth understanding of the distributed environment in the design of technical options have important guidance role, so here to do the next finishing.
1. Cap principle
1.1 Definitions
The CAP is a short name for "consistency,avalilability, Partition tolerance", the contents of which are:
(1) Strong consistency : In the case of multiple copies of the same data in a distributed system, the effect of updating the data is the same as that of only a single copy of data.
(2) Availability : Client Reads/writes to large-scale data systems at any time should be guaranteed to be completed within a limited delay;
(3) partition tolerance : In large-scale distributed data system, the network partition phenomenon, that is, the partition between the machine can not network communication situation is inevitable, so the system should be able to continue to work in this situation.
For a large-scale distributed data system, the CAP three elements are not available, the same system can only achieve two of them, but must relax the 3rd element to ensure that the other two elements are satisfied. Generally in the network environment, the running environment network partition is unavoidable, so the system must have partition tolerance (P) characteristics, so in general in this scenario design large-scale distributed systems, often in the AP and CP in the trade-offs and choices.
1.2 Why is the cap three in a distributed environment not to be combined?
Since the above mentioned for the distributed environment, p is necessary, so the problem can be converted to: if P has been obtained, then C and a can be combined? Can be divided into two situations to deduce:
(1) If the data in this distributed system does not have a copy, then the system must meet the strong consistency conditions, because only the unique data, there is no data inconsistency problem, at this time C and P are available. However, if some services
The machine goes down, it will inevitably cause some data to be inaccessible, and that a will not fit.
(2) If the data in this distributed system is a replica, then if some servers are down, the system can still provide services, that is, a. But it's hard to keep the data consistent, because when you are down, you may
Some data has not been copied to the copy, so the data provided in the copy is inaccurate.
Therefore, in general, according to the specific business to focus on C or a, for the higher consistency requirements of the business, then the access delay time requirements will be low, for the access latency requirements of the business, then the data consistency requirements will be low. The consistency model can be divided into the following categories: Strong consistency, weak consistency, eventual consistency, causal consistency, read-write consistency, session consistency, monotonic read consistency, and monotonic write consistency, so you need to choose the right consistency model for different businesses.
2. Acid principle
Acid is the principle adopted by relational database systems, and its representative meanings are:
(1) atomicity (atomicity): means that a transaction is either executed entirely or not executed at all.
(2) Consistency (consistency): When a transaction begins and ends, the consistency constraint should always be met. For example, if the system requires a+b=100, then if a transaction changes the value of a, then the value of B should be modified accordingly to meet such conformance requirements, and the meaning of C in the cap is different.
(3) transaction Independence (Isolation): If there are multiple transactions executing at the same time, there is no need to know each other's existence, and execution does not affect each other, the transaction need to serialize execution, there is a chronological order.
(4) persistence (Durability): The persistence of a transaction means that the update to the system State is permanent after the transaction has run successfully, and does not rollback the revocation for no reason.
Distributed-cap and acid principles