1. Home
  2. Explore
  3. Computer Science
  4. Distributed Systems Consensus

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Distributed Systems Consensus

Transcript

Have you ever been in one of those group chats,  you know, trying to organize something really   important like uh a surprise party maybe or  some complicated trip? Everyone's throwing ideas   around, but then someone misses a key message  or their phone dies for an hour or, you know,   the worst two people hit send at the exact same  time with totally opposite plans. It just spirals   into chaos, right? Okay. Now, picture that, but  scale it up. Way up. Imagine the group members aren't people but thousands maybe millions of  computers in some huge distributed system and   they all need to agree on one single absolutely  critical piece of data like your bank balance   right or the next command for a power grid or the  real state of some crucial database if you've got   multiple machines trying to update that data at  once and maybe some fail messages get lost maybe   a network cable gets I don't know chewed by a  squirrel this sounds like total utter mayhem

impossible hey everyone welcome to the Deep Dive,  your shortcut to being wellinformed. I'm Alex and   today we're diving into one of computer science's  really fascinating puzzles. How do we get all   these separate systems to actually agree on  something even when everything around them seems   to be well falling apart? And I'm Jordan. Yeah,  we're digging deep into a really foundational idea   today. It's a concept that pretty much underlies  how we build reliable distributed systems. And it's an algorithm that uh well its own creator  famously called it difficult to understand at   first. Ah yeah not exactly encouraging right but  then in this really brilliant move he actually   simplified it himself later on. That's the one  we are talking about Leslie Lamport's Paxos made   simple paper from 2001. This paper is I mean it's  kind of legendary in the field isn't it? because   it took this algorithm Paxos which seemed almost  impenetrable and just stripped it down to its core

logic made it understandable for way more people.  Exactly. Before this paper, Lamport himself said   the original Paxos description was quote Greek  to many readers, which really tells you something   about how abstract and frankly counterintuitive  distributed systems can feel sometimes. It does.   and his whole goal with Paxos made simple was to  show that actually when you look at it the right   way, it's quote among the simplest and most  obvious of distributed algorithms. Simplicity hiding in complexity. I love that. Mhm. And so  our mission for this deep dive is pretty much that   to unpack that elegance. We want to break down  how a bunch of independent processes, you know,   computer, software agents, whatever, can actually  reach a single unchangeable agreement on some   value even when the network is unreliable.  Messages get delayed or lost and computers   themselves can just well crash and burn at any  moment, right? It's all about getting that solid

fault tolerant agreement even in environments that  are basically designed to be chaotic. Okay, so   let's start right at the beginning. What is this  fundamental problem Lamport was tackling? What   exactly is consensus in this, you know, wild world  of distributed systems? Okay, so at its heart,   consensus is really just about agreement. Simple  as that. You've got this collection of processes. Just think of them as separate computers or maybe  virtual machines or even just software things   running on different servers. And these processes,  they can propose values. So one might say, "Hey,   let's deposit $100 into account X." And another  one shouts, "Withdraw $50 from account X at the   same time." Exactly. So the job, the fundamental  task of a consensus algorithm is to make sure that   out of all these competing, maybe conflicting  proposed values, only one single value gets

chosen and that chosen value becomes the single  source of truth for everyone in the system for   that specific decision. It's the final word. Okay,  give us another example. Maybe something really   concrete just didn't nail that idea down. beyond  banks. Sure. Uh, think about a massive online   game. You've got thousands of players running  around, picking up items, changing their gear,   trading stuff. Every single one of those actions  needs to be recorded consistently across maybe dozens of servers spread all over the world.  Yeah. You can't have someone pick up a sword   on one server, but on another server, it looks  like they picked up a shield or someone else got   the sword. Precisely. That would be chaos. So, a  consensus algorithm makes sure that when a player   picks up that rare sword, only one proposed update  for that specific item slot gets chosen and copied   everywhere. It keeps the game world consistent  and fair. Okay, got it. Or think about shared

configuration services like uh Google's Chubby  or Apache Zookeeper. These things act like a   central brain for lots of different applications  in big cloud setups. They use consensus to make   absolutely sure that all the different services  using the configuration always agree on what the   current settings are. You avoid one part of the  system working with old rules while another uses   new ones. That really clarifies the stakes. So  if the goal is reaching this single agreed upon truth, what are the absolute like non-negotiable  rules, the ground rules for any decent consensus   algorithm? Because in those examples, getting  it wrong just isn't an option. You absolutely   cannot have two different realities coexisting.  You nailed it. Safety. Safety is job number one.   Non-negotiable. The paper lays out three really  clear safety requirements. These must always   hold true no matter how bad the network gets or  how many machines fail. First, only a value that

has been proposed may be chosen. Okay, that makes  sense. No phantom values appearing out of nowhere,   right? It has to come from a legitimate source  within the system. No magic numbers, no malicious   inputs getting chosen accidentally. Second,  and this is really the core of consistency,   only a single value is chosen, the one truth rule.  Exactly. This is what stops you from having two   different balances for the same bank account or  two players owning the same unique game item. Once a value is chosen for decision number 135,  no other value can ever be chosen for decision 1,   Kimmel 5. It's locked in, immutable. Okay, one  proposal, one choice, one truth. And third,   a process never learns that a value has  been chosen unless it actually has been. Ah,   no false alarms. Don't tell me we agreed if we  didn't actually agree yet. Precisely. Prevents   false positives. Imagine a server thinking  a critical transaction was finalized when it

wasn't and then acting on that bad info. That  could cause a disaster cascade. This rule is   about demanding absolute certainty before anyone  acts on the outcome. Okay, so safety is all about   correctness, being right, being consistent,  avoiding screw-ups. But a system also has to,   you know, do stuff. It can't just sit there being  safe but useless. That's where livveness comes in,   isn't it? The idea that it doesn't just get stuck  forever trying to agree. That's exactly right. Safety is about never doing anything wrong.  Livveness is about eventually doing something   right. And the goal here is kind of twofold.  First, some proposed value is eventually chosen.   Meaning it doesn't just freeze up. It actually  makes decisions, right? The system makes progress.   It doesn't deadlock forever, right? And second,  if a value has been chosen, then a process can   eventually learn the value. So once the decision  is made, the news spreads, people find out. Yep.

Information propagates reliably so components  can actually use the agreed upon state. Okay.   And I can already feel the tension there. It's one  thing to say only one value is chosen, which you   know sounds hard enough in a messy network, but  then guaranteeing that something eventually gets   chosen and that everyone finds out about it. Even  when messages vanish, networks split, computers crash and reboot randomly. Yeah, that feels like  the real uphill battle. It's like uh trying to get   your whole family to agree on a movie for movie  night, then making sure the movie actually starts   playing and everyone knows it's playing. Even if  the power flickers or the remote gets lost or half   the family wanders off and comes back, forgetting  what movie was even picked. That's a perfect

analogy. It really captures that subtle difficulty  in these truly distributed setups. Even guarantees   that seem simple on the surface become incredibly  challenging because of all that unpredictability.   The network, the individual machines, they're  just inherently unreliable. Okay, so we get   the problem, consensus. We get the goals, safety  and livveness. But you know, anyone who's tried building reliable stuff knows the simplest ideas  often break first. Let's talk about why the easy   ways fail. What's wrong with just, I don't know,  putting one main computer in charge of deciding   everything? the dictator approach. Well, that's  definitely the most intuitive place to start. And   honestly, it works perfectly fine if you assume  nothing ever breaks. You could just designate   one special process, one acceptor. Proposers  send their ideas to the central acceptor. It

picks the first valid one it sees, announces it.  Done. Simple, fast, direct. Yeah, but the second   you said single acceptor, I'm pretty sure alarm  bell started ringing for anyone who's dealt with   realworld distributed systems. That screams single  point of failure. You got it. That's the immediate   glaring flaw. Lamport puts it bluntly. The  failure of the acceptor makes any further progress impossible. If that one central machine crashes  or even just gets cut off by a network problem,   boom, your whole system grinds to a halt. Nothing  new can be decided. And this really highlights   that core challenge of distributed systems. How do  you get reliability and keep things running when   the individual parts are inherently unreliable?  You just can't bet everything on one component.   That's why we build distributed systems in  the first place for fault tolerance. Okay,

so no single points of failure. We're definitely  in a distributed world now. But that world has   its own rules, right? Its own assumptions about  how things work, how they talk to each other.   What's the specific model, the set of assumptions  that the Paxos paper works under? Because it's   obviously not assuming perfect clocks and instant  communication. Not at all. And understanding this   model is key to seeing why Paxos is designed the  way it is and why it's so powerful. The paper assumes what's generally called an asynchronous  non-Byzantine model. Let's unpack that carefully.   Asynchronous means a few critical things.  First, the agents, the computers or processes,   they operate at totally arbitrary speeds. One  might be super fast. Another might be slow   because it's busy. It might even pause for a long  time doing say garbage collection. You just don't   know. Unpredictable timing. Exactly. Second, they  can fail. How? By just stopping. They crash. Pow.

And crucially, they might restart later. But when  they restart, they might not remember everything   they knew before the crash. Ah, like amnesia after  a reboot. Pretty much. And this immediately brings   up a fundamental need. Lamport notes. Since all  agents may fail after a value is chosen and then   restart, a solution is impossible unless some  information can be remembered by an agent that   has failed and restarted. Okay, so they need  some kind of persistent memory, something that survives the crash. Yes, this points directly  to the absolute necessity of stable storage,   someplace where critical information can be  stored reliably even if the power goes out or   the process crashes completely like writing it to  a hard drive or some kind of nonvolatile memory,   not just keeping it in RAM, which gets  wiped. Exactly that. It's fundamental   for data durability in pretty much any serious  distributed system, not just Paxos. In practice,

you achieve this with things like writing to disk,  often using techniques like write ahead logging or   journaling. You make sure the critical data is  safely on disk before you update your in-memory   state. Newer tech like NVMe drives or persistent  memory is changing the game here too, offering   faster, durable storage. But the principle is  the same. The important state, the promises made, the values accepted, they must survive crashes and  be recoverable on restart. Without that memory,   consensus across failures just won't work. Makes  sense. What else does asynchronism imply? It   also applies to the network. The communication  messages can take an arbitrarily long time to   arrive. You send something. It might get there  in milliseconds, might take seconds, might take   minutes. You have no upperbound guarantee. Okay,  slow messages. Messages can also get duplicated.

The network might accidentally deliver the same  message twice. Annoying, but maybe manageable.   And probably the most frustrating part, messages  can just get lost entirely. Poof. Vanished into   the ether. Okay, that's rough. Lost messages,  duplicated messages, unpredictable delays,   crashing nodes. Sounds tough. Is there any  good news in this model? There is one crucial   simplifying assumption. It's non-bzyantine.  This means that while messages can be slow, lost, or duplicated, they are not corrupted.  What arrives is what was sent. And importantly,   the agents themselves aren't malicious. They  might fail by crashing. They might be slow,   but they don't lie. They don't intentionally try  to sabotage the consensus process. Ah, okay. So,   no traders in the camp, just unreliable, sometimes  failing, but ultimately honest participants.   Exactly. Dealing with Byzantine faults where  nodes can lie or act arbitrarily is a whole other

level of complexity. Algorithms like PBFT handle  that, but Paxos operates in this non-byzantine   world. That's a huge difference. Malicious actors  would change everything. But even without them,   just those benign conditions you listed,  the arbitrary speeds, the message delays,   the failures, that makes consensus incredibly  hard. It's not just about one machine dying. It's   about the uncertainty. Is that server slow or has  it crashed? Is my message lost or just delayed? Did I crash and restart and now I'm totally out  of sync? It's like trying to navigate in thick   fog. That's a great way to put it. Uncertainty  is the main enemy here. And to manage this fog,   this uncertainty, the Paxus algorithm defines  three different logical roles or classes of   agents. It's important to remember though that in  a real system, one physical computer can and often   does play all three roles at once. This is more  about separating responsibilities conceptually.

Okay, what are the roles? First, you have the  proposers. These are the ones who actually want   a value to be chosen. They kick off the process.  They propose things like set the balance to $500   or execute transaction 123. They're the idea  generators. Got it. Proposers propose. Second,   the acptors. These are the crucial ones. They're  like the voters or the judges. They receive   proposals. They vote on them. They accept  them. They are the guardians of consistency, enforcing the rules to make sure only one value  gets chosen. Acers accept or reject. And third,   you have the learners. Their job is pretty simple.  Find out which value actually was chosen by the   acptors. Once consensus is reached, learners get  informed. So they can update their own state or   take action based on the agreed upon value. They  need to know the result. Proposers, acceptors,   learners. Okay. Clear roles, logical separation.  Makes sense. Now we already established that

having just one acceptor is fragile. Single point  of failure. So the obvious next step towards   making this fault tolerant is use more acceptors.  Right. Exactly. If one isn't enough, let's use a   group, a committee. So a proposer doesn't just  send its value to one acceptor. It sends it to a   whole set of acceptors. And the absolute key rule  here, the thing that really makes Paxo safe is how we define chosen. A value is considered chosen  when a majority of these acceptters have accepted   it. A majority. Okay. Why specifically a majority?  Why not say demand that all of them agree or maybe   just like two or three? Why is majority the magic  number? Uh this is where the mathematical elegance   really kicks in. It's kind of the core insight.  The paper explains it very clearly because any

two majorities have at least one acceptor in  common. Let's pause there. Imagine you have five   acptors and majority is three. Pick any group of  three acptors. Now pick any other group of three   acres from those same five. Those two groups must  overlap. They have to share at least one acceptor   in common. It's a basic property of sets. Okay.  Yeah. With five, any group of three overlaps with   any other group of three. I see that. Right. So  the rule continues. This works if an acceptor can accept at most one value. So let's say value  A gets chosen. That means at least three acptors   accepted A. Now suppose somehow a different value  B also got chosen. That would mean at least three   acptors accepted B. But because those two groups  of three must overlap, there's at least one   acceptor who would have had to accept both A and  B. But wait, you just said an acceptor can only

accept one value. Exactly. So it's impossible. The  majority requirement combined with the accept only   one value rule mathematically guarantees  that two different values cannot both be   chosen. The overlap prevents it. It's simple but  incredibly powerful. Wow. Okay, that is elegant.   The overlap is the safety net. But it's hang on  that raises another problem, doesn't it? What   if you have multiple proposers? Proposer alpha  sends value X to say acceptors 1 2 3. Proposer beta simultaneously sends value Y to acceptors  3 4 5. If the rule is just like except the first   proposal you get, Lamport calls this the naive  P1 rule, right? Then except one and two except X,   except four and five except Y, except three. Well,  who knows which one arrive first, but it accepts   one of them. But in the end, neither X nor Y gets  a majority of three. You're stuck. Nothing gets

chosen. It's like a hung jury. That is precisely  the deadlock scenario that this simple except the   first rule P1 leads to. It sounds reasonable  initially, but in a distributed world with   unpredictable timing, it just doesn't work  reliably. It kills progress. So, the solution,   which might seem a bit counterintuitive at first,  is this. An acceptor must be allowed to accept   more than one proposal. Wait, but didn't we just  rely on them accepting only one value for safety? How does that work? Ah, good catch. We need a  way to distinguish which proposal we're talking   about. So, we can't just talk about accepting  values anymore. We need to talk about accepting   specific proposals. And the way we do that is  by giving each proposal a unique identifier,   specifically a natural number, a unique strictly  increasing integer. So now a proposal isn't just a   value like X. It's a pair, a proposal number, say  101, a value X, so maybe 101X. This lets acptors

track different attempts or different rounds of  proposals. A value is now considered chosen when   a single proposal identified by its unique number  and its value has been accepted by a majority of   acceptors. Okay. Okay. This feels like it's  getting well significantly more complex now,   but I think I follow. We're not just choosing  X. We're choosing proposal number 101,   which happens to carry the value X, and we need  a majority for that specific proposal. But the crucial thing is still consistency, right? How do  we guarantee that if proposal 101X gets chosen,   then some later proposal, say 105Y, can't also  get chosen for the same decision instance? We   still need that single value guarantee somehow.  This feels like the absolute core of Paxo safety.   It absolutely is. And this is where a Lamport's  step-by-step derivation really shows its strength.   He builds up the safety properties logically,  showing how the final rules are almost forced

upon us if we want consistency. It starts with a  property called P2. If a proposal with value V is   chosen, then every higher numbered proposal  that is chosen has value V. Okay, read that   again slowly. If proposal NV is chosen, then any  later chosen proposal like N plus KV must have   the same value. So V must equal V. Exactly. Once  a proposal like 101X gets chosen by a majority,   this rule P2 says that if any future proposal like  maybe 105 or 110 also manages to get chosen for the same decision instance, it must also carry the  value X. It locks in the value. Once X is chosen,   the only thing that can be chosen afterwards for  this instance is X. It prevents the system from   changing its mind later. Right? That makes sense.  That preserves the single chosen value idea over   time across different proposal numbers. But how  do we enforce that? What if you know in the chaos

proposal 101X is chosen but some acceptor hasn't  quite learned that yet and then proposer beta   comes along with proposal 105 Y and that acceptor  not knowing X was already chosen acceptor 105   Y that seems like it could still cause problems  even if 105 Y doesn't get a full majority itself.   You're right. P2 is the goal, but it's not quite  strong enough on its own as an operational rule   for the acptors. We need something stricter that  applies before a proposal is formally chosen. This leads to P2A. If a proposal with value V  is chosen, then every higher numbered proposal   accepted by any acceptor has value V. See the  difference? It's not just about chosen proposals.   Now, it's about any higher numbered proposal that  gets accepted by any individual acceptor. Even   if that acceptance doesn't lead to a majority  win for that proposal, P2A says it still must   carry the original value V. Oh, okay. So if 101X  was chosen, then no acceptor should ever accept

105 Y. Even if Y is different from X, it has to  accept 105X or nothing at all with number 105.   It tightens the screws on individual acptors.  Exactly. It pushes the consistency requirement   down to the individual acceptor level. But even  P2A has a subtle vulnerability in an asynchronous   world. What if 101X is chosen? Then some proposer  gamma who's maybe slow or was offline wakes up. It   doesn't know X was chosen. It decides to propose  105 Y. Now it sends this 105Y proposal out. What stops an accepter, maybe one that also hasn't yet  learned about 101X being chosen, from accepting   105? Why would violate P2A? Right. P2A describes  what should happen, but not necessarily how to   prevent a proposer from even sending a conflicting  proposal in the first place. Precisely. So we need   the strongest form P2B. If a proposal with value  is chosen, then every higher numbered proposal

issued by any proposer has value V. This is the  ultimate safety guarantee. It says once 101X is   chosen, no proposer should even be allowed to  issue a proposal like 105Y. They must issue   105. If they issue anything with number 105,  it controls the source of proposals. Y okay,   now that sounds hard. How on earth do you enforce  P2B in practice? How do you stop a proposer from   issuing a bad proposal, especially when they might  be disconnected or slow or just haven't heard the latest news about what value X was chosen? It's  like saying once we agree the party theme is '8s,   nobody's allowed to even suggest a disco theme  later, even if they miss the 80s vote. How do   you police their thoughts? Huh? Yeah, it does  sound like thought police, but the mechanism   isn't about policing thoughts. It's about ensuring  proposers gather enough information before they   issue a proposal and getting promises from  acptors to constrain the future. This is

where the crucial invariant P2C comes in. P2C is  the condition that if maintained guarantees P2B   holds true. It's the practical rule that makes  the whole thing work. P2C states for any VNN,   if a proposal with value V and number N is issued,  then there is a set S consisting of a majority   of acptors such that either A, no acceptor in S  has accepted any proposal numbered less than N,   or B is the value of the highest numbered proposal  among all proposals numbered less than N accepted by the acptors in S. Whoa. Okay, that's dense.  Let's try to translate that into like plain   English actions. What does a proposer actually  do to satisfy that? Okay, let's break it down.   Essentially, PTC tells a proposer what it needs to  ensure before it's allowed to issue its proposal,   NV. It needs to check with a majority of acptors.  That's the set S. And for that majority, one of   two conditions must be true. Condition A is the  simple case. None of those majority accepts have

accepted any proposal with a number lower than  N. This means the proposer is basically starting   fresh or at least with a high enough number  to override any past attempts. In this case,   the proposer is free to choose its own value V.  Okay. So, if the coast is clear with a majority,   it can propose whatever it wants. What's condition  B? Condition B is the crucial one for consistency.   It says, if some of those majority acceptors  have accepted proposals numbered less than N, then the value V that the proposer must issue must  be the value from the highest numbered proposal   previously accepted within that majority set S.  Ah so if a previous proposal say 98Z was already   accepted by some of the acersptors in my majority  and 98 is the highest number they've accepted so   far then my new proposal N which is higher  than 98 must carry the value Z. I'm forced   to adopt the value from the latest accepted  proposal. Precisely. This is the mechanism

that propagates a potentially chosen value. If  a value was already on its way to being chosen,   accepted by some, maybe even a majority, any new  proposer trying to use a higher number is forced   to pick up that same value, it prevents them  from introducing a conflicting value. Okay,   that makes sense. It forces convergence. But how  does the proposer find out about these previously   exited values? And how does it stop acceptors  from accepting other older proposals after it has done its check, but before it issues its own  proposal in? There's still a race condition there,   isn't there? Excellent point. This is where the  two-phase nature of the Paxos algorithm comes   in derived directly from needing to satisfy PTC.  A proposer can't just issue NV directly. It has   to do a preliminary phase first. To satisfy PTC,  a proposer needs to do two key things which map

perfectly onto Paxus' phase one. First, it needs  to find out what, if anything, the acceptors have   already accepted. Specifically, it needs to learn  the highest numbered proposal accepted by each   acceptor in some majority that has a number less  than its intended new proposal number n. This is   how it discovers if it needs to use condition  B of P2C and adopt an existing value. Okay. So,   phase one involves reconnaissance checking  the past history with majority. Right. But that's not enough because of the race condition  you mentioned. While the proposer is collecting   this info, an acceptor might accept another  proposal, say with number n1. So the second   crucial part of phase one is that the proposer  needs to control future acceptances. Lamport says   it needs to extract a promise that there won't be  any such acceptances. A promise from the acptors.   Yes. The proposer when it contacts the majority  in phase one with its intended proposal number n

essentially asks them, will you please promise me  that you will not accept any proposals numbered   less than n from now on? Uh it's locking them  down. It's saying ignore the past lower numbers.   I'm taking over from number n onwards. Exactly.  This promise is the genius of the prepare request.   It creates a guarantee that if a majority  of acptors make this promise for number n,   then no proposal with a number lower than n can  ever be chosen in the future because it can never get a majority acceptance, it effectively disables  older potentially conflicting proposals. Okay,   this is clicking now. The two phases make sense.  Can you walk us through the concrete steps? the   actual algorithm, the cinned algorithm as Lamport  calls it. Absolutely. Let's lay out the two phases   clearly. Phase one, prepare, also sometimes  called the promise phase. Step one, a proposer   wants to get a value chosen. First, it picks a  new unique proposal number, N. This n must be

higher than any number it has used before for this  specific consensus instance. You got to keep those   numbers increasing always. Then it sends a prepare  request message containing just this number n to a   majority of the acceptors. Think of it as prepare  for proposal N or can I use number N. Step 1B. An   acceptor receives this prepare request for number  n. It looks at the highest proposal number it has already promised to respond to in a previous  prepare request. Let's call that max promised.   If the incoming n is greater than max promised,  then the acceptor does two things. First, it   updates max promised to n and saves this to stable  storage. This is the promise. Okay. I promise not   to accept any proposal numbered less than n  anymore. Second, it sends a promise response   back to the proposer. This response includes the  promise implicitly by responding positively. And

crucially, it also includes the highest numbered  proposal, say accepted, accepted, that it has   already accepted in phase 2 from some previous  round, if any. If it hasn't accepted anything yet,   it indicates that. Okay, so the acceptor promises  to ignore older stuff and tells the proposer about   the latest thing it actually voted yes on. What  if the incoming n is not greater than the number it already promised? Good question. If n is less  than or equal to matt's promised, the acceptor   has already promised to ignore proposals like n  or even n itself if n equals max promised. So it   simply ignores the prepare request. It doesn't  respond. This prevents it from breaking its   existing higher promise. Phase two, accept. Also  sometimes called the propose phase, step 2 a. Now   the proposer waits for responses to its prepare  request n. If it receives promised responses

from a majority of the acceptors, then phase  one was successful. It got enough promises. It   has clearance to proceed. Exactly. Now it needs to  decide which value V to actually propose. It looks   at all the promise responses it received from the  majority. Here's the key rule. Implementing P2CB.   If any of those responses reported a previously  accepted proposal and accepted accepted,   the proposer must choose the value of accepted  associated with the highest accepted among all the responses. It adopts the value from the latest  accepted proposal it learned about. It's forced   to carry forward the value that might already be  winning, right? However, if none of the responses   from the majority reported any previously accepted  proposal, meaning the coast was clear, P2CA, then   the proposer is free to use its own originally  intended value for V. Okay, so it picks it value V

based on those rules. Then what? Then the proposer  sends an accept request message containing its   chosen pair NV to the same majority of acptors  that send it promises. think okay please accept   proposal number n with value v. Step 2b an  acceptor receives the accept request for nv. It   performs one final check. It accepts the proposal  only if it has not already made a promise in phase   1 b to ignore proposals with number n. In other  words, it checks if n is greater than or equal to its current max promised value. Wait, shouldn't  it be strictly greater? What? Greater than or   equal? Ah, good point. It needs to accept if n is  equal to its max promised. The promise was not to   accept anything less than n. So n itself is okay.  If however the acceptor has made a promise for a   number higher than n, meaning some other proposer  swooped in with a higher prepare request between

phase 1 and phase 2, then n would be less than  its max promise, and it must ignore or reject this   accept request for n. Got it? So if the number n  is still valid according to its latest promise,   what does the acceptor do? If n is valid, n is max  promised, the acceptor accepts the proposal NV.   It records this pair NV in its stable storage as  the highest proposal it has accepted and typically sends an accepted message back to the proposer  and possibly to learners as we'll discuss. And   if that accepted message is received from a  majority of acptors, then the proposer knows   its value V has been officially chosen. Yes. Once  a specific proposal NNV has been accepted by a   majority of acceptors, that value V is considered  chosen for that instance of consensus. Wow. Okay,   that's intricate, but I can see the logic. The  promise in phase one clears the way and gathers

history. Phase two tries to lock in the value,  succeeding only if a higher promise hasn't been   made in the meantime. And you mentioned efficiency  tweaks, like acceptors ignoring prepare requests   if they've already promised higher. Yes, that's  crucial. An acceptor doesn't need to keep track of   or respond to prepare requests with numbers lower  than the highest promise it's already read. That cuts down on unnecessary work and messages. It  just focuses on the highest proposal number it's   aware of. But that stable storage thing you keep  mentioning seems absolutely critical. The acceptor   has to remember its highest promise max promised  and the highest proposal it actually accepted   and accepted if accepted even if it crashes and  restarts. Absolutely non-negotiable. That's the   memory that ensures safety across failures. If  an acceptor forgot its promises or votes after

restarting, it could easily accept conflicting  proposals and break the whole consistency   guarantee. Paxos relies fundamentally on acptors  having durable memory. What about proposers? Do   they need stable storage, too? Interestingly, no,  not for safety. A proposer can actually forget   everything about a proposal attempt if it fails  or gives up. It just needs to ensure that if it   tries again later, it uses a new, higher proposal  number. It can always abandon a proposal number without breaking safety. This makes proposers  more lightweight and easier to manage. Okay,   so we've meticulously walked through how a value  gets chosen. The acptors guided by the proposers   reach the state where a majority agrees on a  specific NV. But then what? How do the other   components, the learners, actually find out  what value ended up being chosen? Knowing   it's chosen somewhere isn't useful if you don't  know what it is, right? Learning the chosen value

is the final practical step. And there are a few  different ways learners can get this information,   each with different trade-offs in terms of speed  and network traffic. The simplest, maybe fastest   way is for every accepter as soon as it accepts  a proposal NV to just tell all the learners about   it. Hey learners, I just accepted Envy. A learner  then listens to these accepted messages. Once it sees the same proposal accepted by a majority  of acptors, it knows that value has been chosen.   Okay. Direct broadcast from acceptors to all  learners seems fast but also potentially noisy,   right? If you have say five acptors and 100  learners and three acptors form the majority,   that's three 100 Echo 300 messages just  to announce one chosen value. Seems like   a lot. It can definitely be a lot especially if  consensus is happening frequently. That N squared

kind of communication cost exceptors XLarners can  become a bottleneck in large systems. So what are   the alternatives to cut down on that message  storm? Well, since we're in a non-byzantine   world where nodes generally don't lie, learners  can trust each other. A common optimization is to   designate one or more distinguished learners.  Instead of acceptors shouting to everyone,   they just send their accepted messages to this  specific distinguished learner or small set of them. Ah, like funneling the information through a  central point. Exactly. This distinguished learner   collects the acceptances. Once it sees a majority  for a proposal NV, it then informs all the other   learners that V has been chosen. That sounds  way more efficient. If you have five acptors   and a 100 learners, the acptors send maybe three  messages to the distinguished learner. Then that   learner sends 99 messages to the others. So 3  + 99 equals 102 messages, much better than 300,

right? The communication cost drops significantly,  roughly to the sum of acptors plus learners   instead of the product. But there's a trade-off,  isn't there? Yeah. Now that distinguished learner   looks like a potential bottleneck or even a single  point of failure for learning the value. If it   crashes or gets slow, nobody finds out precisely.  So a common compromise is to use a small set of distinguished learners. Acceptors send to all of  them. They coordinate amongst themselves and one   or more of them inform the rest. It gives you  better reliability than just one without the   full n squared cost. Many real systems use  something like this. Makes sense. sort of a   balance. But what if despite all this, maybe due  to really bad luck with message loss or crashes,   a value does get chosen, but a specific learner  just never hears about it. Can I get stuck forever

ignorant? It's possible, though unlikely. In  a well functioning system, a learner could try   asking the acceptors directly, hey, what's the  highest proposal you accepted? But even then,   if some acceptors are down, it might not be able  to confirm if a majority was reached. If a learner   really suspects a value might have been chosen,  but it doesn't know what it is and it absolutely   needs to find out now, it can take a proactive  step. It can essentially ask a proposer or act as one itself to run the entire Paxos algorithm  again for that specific consensus instance number.   uh like triggering a revote just to be sure  kind of by initiating a new proposal with a high   enough number, it will force the system to either  converge on the value that was previously chosen   because of the P2C rule forcing proposers to adopt  previously accepted values or if no value was ever

chosen, it will cause some value to be chosen now.  Either way, the learner will eventually learn the   result of this new round. It's a way to actively  force the information out if passive learning   fails. Okay, we've spent a lot of time on safety,  making sure the answer is right, only one answer   is chosen, and Paxo seems incredibly robust there  with all those logical properties and phases,   but what about progress, that livveness goal,  making sure an answer is eventually chosen, because I can still imagine this system  getting stuck, right? Even if it's safe,   it might just spin its wheels. You're absolutely  right to bring that up. This leads us to a classic   and somewhat notorious problem in distributed  systems, the possibility of live lock.   Live lock is different from deadlock. In deadlock,  everything stops. In LiveLock, processes are still   active. They're sending messages. They're  consuming CPU, but they're not making any

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent