TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Paxos in 25 Lines

259 pointsby Cieplakabout 8 years ago

14 comments

GeneralMayhemabout 8 years ago
This is missing what to me is the most important part of the algorithm: a quorum of acceptors must propagate writes to the learners. With just what&#x27;s shown here, you&#x27;re not tolerant to network partitions that cause a subset of the &quot;accept&quot; messages to be lost.<p>That process can of course be optimized in a number of ways that drastically cut down on the network overhead as compared to the naive MxN write pattern, but what&#x27;s written here is not safe on its own.
评论 #13926546 未加载
评论 #13925550 未加载
elvinyungabout 8 years ago
I realize this is pseudocode, but I still feel like the bigger challenge is not in implementing a theoretically correct Paxos, but a production-ready one. It&#x27;s probably pretty well-known the Chubby[1] team&#x27;s experiences dealing with unexpected complexity from using Paxos in production.<p>A choice quote: &quot;While Paxos can be described with a page of pseudo-code, our complete implementation contains several thousand lines of C++ code.&quot;<p>1: <a href="https:&#x2F;&#x2F;static.googleusercontent.com&#x2F;media&#x2F;research.google.com&#x2F;en&#x2F;&#x2F;archive&#x2F;paxos_made_live.pdf" rel="nofollow">https:&#x2F;&#x2F;static.googleusercontent.com&#x2F;media&#x2F;research.google.c...</a>
评论 #13925199 未加载
TuringTestabout 8 years ago
<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Paxos_(computer_science)" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Paxos_(computer_science)</a>
bfungabout 8 years ago
<p><pre><code> 1 proposer(v): 2 while not decided: 2 choose n, unique and higher than any n seen so far </code></pre> 26 lines.<p>It&#x27;s pseudocode, so not really only 26 lines as it needs some more supporting functions to &quot;choose n, unique and...&quot; and other stuff to make setting variable states atomic.<p>Good way to explain the algo though.
评论 #13924765 未加载
评论 #13924212 未加载
trompabout 8 years ago
Curiously, Paxos takes exactly as many lines as a self contained interpreter for a pure functional programming language, written in C :-)<p><a href="http:&#x2F;&#x2F;www.ioccc.org&#x2F;2012&#x2F;tromp&#x2F;tromp.c" rel="nofollow">http:&#x2F;&#x2F;www.ioccc.org&#x2F;2012&#x2F;tromp&#x2F;tromp.c</a><p><a href="http:&#x2F;&#x2F;www.ioccc.org&#x2F;2012&#x2F;tromp&#x2F;hint.html" rel="nofollow">http:&#x2F;&#x2F;www.ioccc.org&#x2F;2012&#x2F;tromp&#x2F;hint.html</a>
gosubplabout 8 years ago
For me this shows the difference between theoretical setting and what you would want to do in practice. I have been following 6.824 (where this is sourced from), to learn something about distributed systems programming and it was great fun to shed a lot of figurative sweat to convert those 26 (actually) lines into working &quot;production&quot; code. Hundreds lines of code, because in real-life we have packet loss, network partitions, etc. But the pseudo-code in the link itself is correct, however, it doesn&#x27;t tell the whole story.<p>Now I am repeating that experience, as Akka project contributor ( <a href="http:&#x2F;&#x2F;akka.io&#x2F;news&#x2F;2017&#x2F;03&#x2F;17&#x2F;akka-2.5.0-RC1-released.html" rel="nofollow">http:&#x2F;&#x2F;akka.io&#x2F;news&#x2F;2017&#x2F;03&#x2F;17&#x2F;akka-2.5.0-RC1-released.html</a> ) on getting delta-CRDTs into Akka. And again - what was a few lines of pseudo-code in the original paper, or even tens of lines of real code but in some ideal setting ( <a href="https:&#x2F;&#x2F;github.com&#x2F;CBaquero&#x2F;delta-enabled-crdts" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;CBaquero&#x2F;delta-enabled-crdts</a> ) is becoming literally thousands lines of &quot;production grade&quot; code.<p>Finally - I wholeheartedly recommend the 6.824 course to anyone interested in distributed systems. Even if you don&#x27;t like strong consistency, you&#x27;ll learn a lot about testing and debugging distributed systems, the knowledge you can re-use later in your career.
Maroabout 8 years ago
Here&#x27;s a version I wrote in C++ for ScalienDB about 5-6 years ago, this startup has since folded so it&#x27;s dead code:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;scalien&#x2F;scaliendb&#x2F;tree&#x2F;master&#x2F;src&#x2F;Framework&#x2F;Replication" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;scalien&#x2F;scaliendb&#x2F;tree&#x2F;master&#x2F;src&#x2F;Framewo...</a><p>Paxos: for replicating data<p>PaxosLease: for negotiating a lease, eg. leader<p>Quorum: pluggable &quot;majority&quot; rules, not that important<p>ReplicatedLog: use Paxos for each append, initiated by leader
评论 #13925519 未加载
barhunabout 8 years ago
everyone, please, read the following blog post before using any &#x27;wow!&#x27;s in your next exclamation:<p>RAFT Explained – Part 1&#x2F;3: Introduction to the Consensus Problem <a href="http:&#x2F;&#x2F;container-solutions.com&#x2F;raft-explained-part-1-the-consenus-problem&#x2F;" rel="nofollow">http:&#x2F;&#x2F;container-solutions.com&#x2F;raft-explained-part-1-the-con...</a><p>&quot;While Paxos can be described with a page of pseudo-code, our complete implementation contains several thousand lines of C++ code.&quot;
jlebrechabout 8 years ago
I miss numbed code, cba scrolling up to a line and doing: end, return, space space, delete, enter, mouse, space space, end.<p>just type 8.5: code here<p>(float to insert between lines)<p>also no nesting.<p>then run a processor like go-fmt that checks the format for you.<p>and use the directory structure for class and methods, directory is a class, and a filename is a method.
jdnierabout 8 years ago
Or if you&#x27;re interested in the opposite of pseudocode, here&#x27;s a TLA+ spec for Paxos.<p>Related to yesterday&#x27;s TLA+ video post <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=13918648" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=13918648</a>
评论 #13927216 未加载
krat0sprakharabout 8 years ago
Interesting! This should be renamed to Paxos Pseudo-code in 25 lines.
nojvekabout 8 years ago
Can someone explain Paxos to layman. What is it even supposed to do?
hubert123about 8 years ago
This is what I mean when I tend to say that all scientific papers should have a minimal reproducable working sample with instructions attached. Lets say I am interested in dam building with turbines and all its glory: One would assume that this is really complex cross cutting tech, but I still firmly believe that if you cant show me how to build a tiny sample dam that powers my mobile phone or my computer, you havent done your part to make your theory sufficiently reproduceable.
dpc_pwabout 8 years ago
Here&#x27;s one in 1 line:<p>run_paxos()
评论 #13925777 未加载