Distributed Systems (Distributed Systems) architecture basic theory

table of Contents

CAP theorem

The CAP theorem is the most basic and most critical theory in the design of distributed systems. It pointed out that distributed data storage cannot meet the following three conditions at the same time.

  1. Consistency : Either get the most recently written data or get an error for each read.
  2. Availability (Availability) : Every request can get a (non-error) response, but there is no guarantee that the latest written data is returned.
  3. Partition tolerance : Although any number of messages are lost (or delayed) by the network between nodes, the system continues to operate.

In other words, the CAP theorem states that in the presence of network partitions, consistency and availability must be selected. When there is no network failure, that is, when the distributed system is running normally, consistency and availability can be satisfied at the same time.

Mastering the CAP theorem, especially being able to correctly understand the meaning of C, A, and P, is very important for system architecture. Because for distributed systems, network failures are inevitable, how to maintain the system to operate in accordance with normal behavior logic when a network failure occurs is particularly important. You can combine actual business scenarios and specific needs to make trade-offs.

In other words, the CAP theory mentions that only two needs can be met at the same time, and there will never be an intersection of the three. For example: MySQL, which pursues CA, lacks partition tolerance, leading to unsuccessful restart of split brain between clusters, which determines the bottleneck that it should work in the same local area network; another example: Cassandra, which pursues AP It did not achieve strict consistency, but it shines in cross-regional and cross-data center high availability, or this is one of OpenContrail's original selection considerations, after all, this fits its vision of heterogeneous cloud network integration. At the same time, Cassandra also supports adjustable consistency, which can be regarded as adaptation to some application scenarios, which is better than nothing.

For example, for most Internet applications (such as portals), because of the large number of machines, scattered deployment nodes, network failures are normal, and availability must be guaranteed, so the only way to guarantee service APs is to abandon consistency. For banks and other scenarios that need to ensure consistency, the CA and CP models are usually weighed. The CA model is completely unavailable when the network fails, and the CP model has partial availability.

Insert picture description here

  • CA (consistency + availability) : Such a system focuses on consistency and availability, and it requires very strict consensus agreements, such as "two-phase commit" (2PC). The CA system cannot tolerate network errors or node errors. Once such a problem occurs, the entire system will reject the write request, because it does not know whether the opposite node is down or it is just a network problem. The only safe way is to make yourself read-only.

  • CP (consistency + partition tolerance) : Such a system focuses on consistency and partition tolerance. It focuses on the consensus protocol of most people in the system, such as Paxos algorithm (Quorum-like algorithm). Such a system only needs to ensure that most of the nodes have the same data, and a few nodes will become unavailable when they are not synchronized to the latest version of the data. This can provide part of the usability.

  • AP (availability + partition tolerance) , such a system cares about availability and partition tolerance. Therefore, such a system cannot achieve consistency, and data conflicts need to be given, and data versions need to be maintained if data conflicts are given. Dynamo is such a system.

Insert picture description here

BASE theory

The BASE theory is the result of the balance between consistency and availability in the CAP principle:

  • Basically Available (basically available) : refers to the distributed system in the event of unpredictable failures, allowing partial loss of availability, which is not equivalent to the system is not available.
  • Soft state : refers to allowing the data in the system to have an intermediate state, and that the existence of the intermediate state will not affect the overall availability of the system, that is, allowing the system to delay the process of data synchronization between data copies of different nodes. Time.
  • Eventually consistent (eventually consistent) : It is emphasized that all data copies can finally reach a consistent state after a period of synchronization. Therefore, the essence of final consistency is that the system needs to ensure that the final data can be consistent, but does not need to ensure strong consistency of system data in real time.

The BASE theory comes from the summary of the distributed practice of large-scale Internet systems, and is gradually evolved based on the CAP principle. The core idea is that even if strong consistency cannot be achieved, each application can adopt an appropriate method to make the system achieve ultimate consistency according to its own business characteristics.

In general, the BASE theory is oriented to large-scale, highly available and scalable distributed systems. It is contrary to the traditional ACID characteristics of transactions. It is completely different from the ACID strong consistency model, but is obtained by sacrificing strong consistency Availability and allow data to be inconsistent for a period of time, but eventually reach a consistent state. At the same time, in actual distributed scenarios, different business units and components have different requirements for data consistency. Therefore, in the specific distributed system architecture design process, ACID features and BASE theory are often combined together.

Guess you like

Origin blog.csdn.net/Jmilk/article/details/108692724