Wonderful paper: Distributed consensus protocol-Paxos


Let me tell a little story first. There is a super man named Leslie Lambert who won the Turing Award. He has been studying the distributed field. The consistency problem in the distributed environment has always been difficult to solve. This buddy wrote a paper called "The Part-Time Parliament", which is also the "part-time parliament . " This paper mentions a Paxos algorithm, which can solve the problem of data inconsistency caused by machines in the cluster that may be offline at any time in a distributed environment. But this uncle is very weird. He wrote an algorithm paper abruptly into a story-as you can tell from the name of the paper-there is no mathematical symbol in the whole paper. As you can imagine, the top academic journals did not accept his papers at all.

Those who are interested can reply in the background: paxos , please read this algorithm paper with only 11 pages and no formulas.


The function of the distributed consensus protocol is to allow all nodes to reach a consensus in the event of an abnormal network. No matter what abnormality occurs in the network, all nodes in the cluster can reach agreement on certain information as long as they pass this agreement.

Currently, the widely used distributed consensus protocols are:

  • Paxos

  • ZBA

  • Raft

Paxos protocol

The Paxos protocol requires several roles to handle the corresponding tasks:

  • Proposer

  • Decision Maker Acceptor

  • Learner

We set up three roles at the same time in each node. When the data/opinions of different nodes are inconsistent, the three roles will reach agreement through:

  • Prepare proposal stage: The proposer initiates a proposal to the decision maker.

  • Accept decision-making stage: The decision maker accepts the proposal and informs all learners.


Scenario hypothesis: Now Liu Bei, Guan Yu, and Zhang Fei are commanding the three armies, and each received a secret letter from the military division Zhuge Liang, asking them to attack. Liu Bei and Guan Yu received an attack against Cao Cao, and Zhang Fei received an attack against Zhou Yu. How can this be neat? Note that the information transmission is unstable at this time and the messenger may be killed.

Prepare proposal stage


  • Prepare proposal stage:

    The first step of the proposal stage: Proposer of all nodes More than half of the Acceptor decision makers of all nodes initiate a proposal. The main content of this proposal is a number.

    Sun Gan, who followed Liu Bei, simultaneously sent a secret letter to the three bosses of Liu Guanzhang, the number is 666; Mi Zhu also sent it, the number is 555, and the number of Fazheng is 111.

    Proposal phase of the second step :All AcceptorsThe decision maker responds to the proposal with the highest number on the opponent.

    During the period, two messengers hung up, so Liu Bei received secret letters from Sun Qian, Mi Zhu and Fazheng, Guan Yu received Sun Qian and Fazheng's, and Zhang Fei received Mi Zhu and Fazheng's. Then each opponent with the highest number replied a letter: I have received it.

Accept decision stage


  • Accept decision stage:

    The first step in the decision-making stage: receive more than half of the decision-makers  Acceptor reply proponent  Proposer, the number and content of its proposal again to send more than half of the decision-makers  Acceptor .

    Among the three of Sun Gan, Mi Zhu and Fazheng, only Sun Gan received more than one version of feedback, so he sent the information he received to Liu Guanzhang again. Unfortunately, this time only about Yu received it.

    The second step of the decision-making stage : only if the decision-maker  Acceptor receives the decision proposal with the highest number in the previous response, then he should accept the proposal. At the same time, he needs to inform all learners Learner .

    image

  • Guan Yu received the proposal he had responded to before. This was a message from Sun Qian about attacking Cao Cao. He accepted the proposal and informed all the learners (soldiers) of the proposal. At this time, all the nodes reached an agreement on who to attack and happily attacked Cao Cao.


Some people say, why is it so complicated? Yes, Paxos is notoriously complex, this is already a super simplified version. The example of Liu Guanzhang above is actually a Chinese translation of "Byzantine Generals' Problem " .

But this is one of the most extensive distributed consistency solutions at the time and even now. It solves a super difficult problem: how to make each node in the cluster reach a unified opinion in the case of abnormal information transmission (machine hangs, message delay, loss, duplication, disorder, etc.). Based on the above basic logic and various restriction rules, Paxos can ensure that no matter any exception occurs within the cluster, the entire distributed system can reach a consistent decision on a certain information.

But Paxos is too strenuous, too difficult to understand, and there are too many nodes, which is very troublesome.


Guess you like

Origin blog.51cto.com/15127541/2664932