Distributed technology stack 1.1-basic theory of CAP ideal to BASE reality

introduction

Distributed technology is the cornerstone of the Internet. Especially for hundreds of millions of visiting websites, the single-machine background is far from meeting the demand. Distributed technology provides the technical possibility of multi-machine, multi-level load balancing and horizontal scaling. However, compared with a stand-alone system, distributed systems have more complex and uncertain business interactions.

1 CAP ideal

The problem domain facing the distributed system can be summarized into three points: consistency (C: Consistency), availability (A: Availability), and partition tolerance (P: Partition tolerance). These are also three problems that need to be solved in distributed systems, starting with the first letter, also known as the CAP theory.

1.1 Consistency

When the data is updated in one copy, the other copies must be updated. It can be divided into strong consistency and weak consistency. The consistency in CAP theory refers to strong consistency.
Strong consistency
Strong consistency means that the modification of any copy of the data will be synchronized to the entire system immediately, and subsequent requests are the latest data; it is like the consistency of the operation and the process data. Strong consistency poses challenges to concurrency and availability, and it is basically difficult to meet strong consistency, availability, and partition fault tolerance at the same time.
Weak consistency
Weak consistency is a modification of a copy of data, which does not ensure synchronization to the entire system, and subsequent requests may not be the latest data. There is no need for consistency, which is the easiest to achieve.

1.2 Usability

The service provided by the system is always in a serviceable state, and every request can get a correct response.

1.3 Partition fault tolerance

When there are nodes in the system that cannot communicate due to network reasons, the system can still continue to run.

1.4 CAP trade-off

Carefully analyze the CAP theory. In reality, it is impossible to take care of the three at the same time, so usually the three are left out of the two.
CA without P
requires strong consistency and availability at the same time. But at this time it is no longer a distributed system, but a stand-alone system! So distributed is impossible without considering partition fault tolerance.
It
is feasible for CP without A to sacrifice availability while satisfying strong consistency and partition fault tolerance. This is the case for many distributed transactions in distributed relational databases.
It
is also feasible for AP wihtout C to sacrifice strong consistency while satisfying high availability and partition fault tolerance. Many NoSQL models are of this type.

2 BASE reality

Since CAP cannot be satisfied at the same time, the ideal is plump and the backbone of reality. Therefore, the BASE principle has become the CAP's moderate choice, that is, basically available (Basically Availble), soft state/soft-state, and eventual consistency (Eventual Consistency).

2.1 Basically usable

Distributed systems are allowed to lose part of their availability in the event of unpredictable failures.
Compared with the CAP requirement system is available, the emphasis here is to allow some unavailability. For example, when a server in a certain area goes down, users in this area are allowed to be unavailable, but most other areas are available, which is not allowed in CAP theory. Another example is when e-commerce websites promote shopping peaks during some festivals, in order to ensure the stability of the shopping system, some consumers may be directed to a downgraded page (for example, a page without product review data).

2.2 Soft state/flexible transaction

Allow the system to have an intermediate state, and the intermediate state will not affect the overall availability of the system.
Soft state is a weak consistency requirement. For example, in distributed storage, there are generally at least three copies of a piece of data. The delay that allows the synchronization of copies between different nodes is a manifestation of soft state; in addition, the number of copies may be greater than or less than three at some time is also a manifestation of soft state.

2.3 Eventual consistency

After a certain period of time, all data copies in the system can finally reach a consistent state.
Ultimate consistency is a special case of weak consistency, a moderate result of strong and weak consistency; it is also the ultimate goal of soft state. For example, although the number of copies in distributed storage fluctuates at a certain moment, it will eventually reach a stable number state.

Guess you like

Origin blog.csdn.net/fs3296/article/details/105414310