当前位置:网站首页>Distributed base theory

Distributed base theory

2022-07-06 00:53:00 It blade out of sheath

Original website :

brief introduction

        This article introduces BASE theory .

        For business systems , We often choose to sacrifice consistency for system availability and partition fault tolerance . But the point here is , So-called “ Sacrifice consistency ” It's not all about giving up data consistency , It's sacrifice Strong consistency Exchange for Weak consistency .

        Base theory : Basic available (Basically Available), Soft state (Soft State), Final consistency (Eventually Consistent)

Basic Available 

        Suppose the system , There was an unforeseen breakdown , But it still works , Compared with a normal system, there are the following losses :

  • Loss of response time : Example : Normal search engines 0.5 Seconds to return the result to the user , And basically available search engines can be found in 2 Second action returns the result .
  • Loss of function : Example : On an e-commerce website , Under normal circumstances , Users can successfully complete every order . But when it comes to the promotion period , In order to protect the stability of the shopping system , Some consumers may be directed to a degraded page .

Soft State

Hard state : Compared with atomicity , The data copies of multiple nodes are required to be consistent .

Soft state : Allow data in the system to have intermediate states , It is considered that this state does not affect the overall availability of the system , That is to say, the system is allowed to have data delay in data copies of multiple different nodes .

Eventually Consistent

        It says soft state , Then it can't be soft all the time , There must be a time limit . After the deadline , Data consistency should be guaranteed for all copies , So as to achieve the final consistency of data . This time period depends on the network delay 、 System load 、 Data replication scheme design and other factors .

In practical engineering practice , The final consistency is divided into 5 Kind of :

term explain
Causal consistency (Causal consistency) If node A After updating some data, the node is notified B, Then the node B Later, the access and modification of the data are based on A Updated value . meanwhile , And nodes A Nodes without causality C There are no such restrictions on data access .
Read what you have written (Read your writes) node A After updating a data , It always has access to the latest values it has updated , Instead of seeing the old value . Actually, it's also a kind of causal consistency .
Conversation consistency (Session consistency) Session consistency frames the process of accessing system data in a session : The system can guarantee the same effective session “ Read what you have written ” The consistency of , in other words , After performing the update operation , The client can always read the latest value of the data item in the same session .
Monotonous reading consistency (Monotonic read consistency) If a node reads a value of a data item from the system , Then the system should not return the older value for any subsequent data access of the node .
Monotonous writing consistency (Monotonic write consistency) A system should be able to ensure that writes from the same node are executed sequentially .

        In practice , this 5 These systems are often used in combination , To build a distributed system with ultimate consistency .

        actually , It's not just distributed systems that use ultimate consistency , Relational database in a certain function , Also using final consistency . Such as backup , The database replication process takes time , In this replication process , The value read by the business is old . Of course , In the end, data consistency was achieved . This is a classic case of ultimate consistency .

        ACID It can guarantee the strong consistency of transactions , That is, the data is consistent in real time . This is no problem in local transactions , In distributed transactions , Strong consistency will greatly affect the performance of distributed systems , So the distributed system follows BASE Theory is enough .

        Different business scenarios of distributed systems have different requirements for consistency . Such as in the trading scenario , It requires strong consistency , At this point you need to follow ACID theory , And send SMS verification code after registration , There's no need for real-time consistency , So follow BASE Theory is enough .

        According to specific business scenarios , stay ACID and BASE Find a balance between .

Other websites

《 from Paxos To Zookeeper Principle and practice of distributed consistency 》

原网站

版权声明
本文为[It blade out of sheath]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140205072949.html