CAP Principles for Distributed Systems

 (It is not easy to write, please indicate when reprinting: http://shihlei.iteye.com/blog/2411612)

I. Overview

Distributed system (multiple servers coordinate with each other through the network to form a system that provides services as a whole)

 

(1) CAP principle: Any network-based data sharing system can only satisfy at most two of the three elements of data consistency, availability, and partition tolerance.

 

(2) CAP explanation:

Consistency: Whether the replicas of the data are consistent on all servers. 

Availability: Whether the data is successfully updated within a certain period of time.

Partition tolerance: 

Partitioning: Data exists only on some of the servers.

Partition container: Data is stored in a partition, and there is a fault (slow network, slow processing, or network unavailable), which makes partition data unavailable for some services. Is it tolerable?

 

Two CAP principles explained

(1) Explain:

1) Satisfy CA: If data is written to multiple copies, the writing must be successful, and it is required that no failure will cause partition (in fact, P cannot be guaranteed, but the probability of P is relatively low)

2) Satisfy CP: (strongly consistent) If all replicas are not successfully written, the processing is considered successful, otherwise it is considered as failure (the probability of errors increases, and the availability decreases)

3) Satisfy AP: (weak consistency) If all copies are partially written successfully, the processing is considered successful (data is inconsistent in each copy, and the consistency decreases)

 

(2) Practice:

1) The architecture needs to be chosen according to the business type, and do not spend energy designing a distributed system that meets CAP at the same time.

2) The distribution is a system. The probability of partition generation is small, but it is inevitable. Therefore, it is necessary to choose between availability and consistency. At present, most system business situations generally compromise consistency in exchange for high availability.

3) In order to solve the problem of reduced availability caused by strong consistency, the current compromise strategy is the eventual consistency proposed by the BASE principle.

 

Three BASE principles

(1) Principle:

Basicly Available

Soft state

Eventually consistent

 

(2) Explain:

Some replicas are successfully written and considered as successful. Through the compensation mechanism, the failed replicas can be successfully written within a certain period of time.

 

4. Conflict Handling About Consistency

(1) Scenario:

To modify the same data through multiple servers, it is necessary to ensure that the modifications are performed in the same order on all replica servers, so that the eventual consistency on all replicas is reliable.

 

E.g:

Action 1 Execute: A machine modifies data record A status set to valid

Action 2 performed later than 1: Machine B modifies data record A status set to obsolete

 

Without conflict handling, some replica A is obsolete (normally desired result), and some replica A is valid (because the synchronization operation of operation 1 arrives at the replica later than operation 2 due to the fault light).

 

(2) Solution:

        • Distributed locks: Simultaneous modifications are not allowed.

        • Paxos: A message-based consensus algorithm that guarantees the same update order on replicas.

        • Based on MQ: messages are written to MQ first. Since MQ has a natural order, operations must be executed in order.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326201695&siteId=291194637