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.

Implementing a distributed key-value store on top of implementing Raft in Go

272 pointsby simjuealmost 2 years ago

15 comments

Xeoncrossalmost 2 years ago
These kinds of posts are my favorite part of HN. The deep dives into LLM&#x27;s, state machine theory, fourier transforms, locking data structures, and memory allocation that is miles above the basic posts around the internet you get with searching - but not quite a full book yet.<p>The author spent 7 months tinkering and cared enough to come back and share that with us.
评论 #36071027 未加载
评论 #36071660 未加载
hintymadalmost 2 years ago
A side topic: how can a company find people like the author, who can really articulate how to build a system? I&#x27;ve been interviewing senior engineers for years, and more than 95% of them, if not more, are really box drawers. They throw terms around confidently but fail miserably the moment I ask for specifics. No, I don&#x27;t ask for details like how Raft works. That level of details probably would fail all the candidates. Just simple things like how you organize the data, how you route the traffic, how you manage metadata, or how your data path keeps metadata in sync. Really basic ones, yet most interviewers fail. Indeed, the more senior they are, the more likely they lose touch of the details -- even those who claim to work on distributed databases.
评论 #36073564 未加载
评论 #36075999 未加载
评论 #36073670 未加载
评论 #36076648 未加载
评论 #36073552 未加载
评论 #36074173 未加载
评论 #36073500 未加载
评论 #36077850 未加载
评论 #36075269 未加载
fredski42almost 2 years ago
Here is nice interactive and visual representation of how raft works: <a href="http:&#x2F;&#x2F;thesecretlivesofdata.com&#x2F;raft&#x2F;" rel="nofollow">http:&#x2F;&#x2F;thesecretlivesofdata.com&#x2F;raft&#x2F;</a>
评论 #36094168 未加载
评论 #36072382 未加载
cheeseprocedurealmost 2 years ago
I was lucky enough to take David Beazley&#x27;s &quot;Rafting Trip,&quot; a five-day training course that guides each student through building their own Raft implementation from scratch:<p><a href="https:&#x2F;&#x2F;www.dabeaz.com&#x2F;raft.html" rel="nofollow">https:&#x2F;&#x2F;www.dabeaz.com&#x2F;raft.html</a><p>I&#x27;d recommend the course to anyone with development experience working with or near distributed systems. David is a fantastic instructor and facilitator, and the blend of student backgrounds led to some great learning and discussion.<p>(I have no financial or personal interest here; I just loved the course.)
评论 #36080966 未加载
samsquirealmost 2 years ago
Thank you for the write up eatonphil.<p>I experimentally implemented Raft in Java but I am not very confident that I did it correctly.<p>I wish there was a way to implement stateful programs that guarantee &quot;forward progress&quot; and are &quot;steady state systems&quot;. I think essentially a state machine that cannot be trapped in a state. Debugging the absence of something of forward moving progress or lack of causation is very difficult.<p>When there&#x27;s essentially different actors in the system and they can interact with eachother by communicating, they each have a number of states they can get into. There&#x27;s no guarantee that the system shall converge on a state that forward progress can be made. Maybe TLA+ is the right answer here.<p>YMMV but I think (my) reasoning over stateful systems is rather difficult, I think there&#x27;s lots of hidden states that we cannot easily detect or reason about because they&#x27;re in our blind spots. Especially related to synchronization. I think it&#x27;s part of what makes multithreading and distributed systems so hard, because every component can be in a different state and if something is not where it is expected to be, the baton doesn&#x27;t get passed to the correct state. If you check for something too early, you have a race condition.<p>If we could see in slow motion what was going on, an interaction between different actors, we could work out why something happens the way it does. But usually the logs are too numerous to get to this detail. I think animation can save us, but what does a Raft animation look like?<p>How often have you seen an endless spinner? It&#x27;s as if a completion event was raised but didn&#x27;t get detected and the system is waiting for something that shall never occur. I want this kind of error to be impossible. This is one form of hidden state that prevents progress.<p>I wrote an eventually consistent mesh protocol in Python and tested it with Jepsen, it is not linearizable because the consistency level is &quot;eventually consistent&quot;.<p>I don&#x27;t understand how Raft can scale writes or reads across multiple machines due to the round trip time talking to other nodes.
评论 #36075703 未加载
评论 #36073642 未加载
评论 #36073901 未加载
评论 #36073539 未加载
restlakealmost 2 years ago
Cool post. Wonder if it would have helped to take a look at the MIT distributed systems course on the web and YouTube - one of the projects is exactly this (Go Raft implementation)<p><a href="https:&#x2F;&#x2F;pdos.csail.mit.edu&#x2F;6.824&#x2F;labs&#x2F;lab-shard.html" rel="nofollow">https:&#x2F;&#x2F;pdos.csail.mit.edu&#x2F;6.824&#x2F;labs&#x2F;lab-shard.html</a>
评论 #36073080 未加载
bit_flipperalmost 2 years ago
Your note about encoding&#x2F;gob being inefficient is somewhat accurate for how you&#x27;re using it, but I want to talk a bit about how you could improve your use.<p>encoding&#x2F;gob is intended for streams, not stateless marshals&#x2F;unmarshals. The first thing that is sent over the stream is the type information the receiver should expect, that&#x27;s why your payload was so large. After the first type is received, subsequent messages are much smaller. You can see this by extending your example to do multiple writes; each write after the first is only 10 bytes: <a href="https:&#x2F;&#x2F;play.golang.com&#x2F;p&#x2F;Po_iaXrTUER" rel="nofollow">https:&#x2F;&#x2F;play.golang.com&#x2F;p&#x2F;Po_iaXrTUER</a><p>You have to plan differently, but you could get large improvements to transmission sizes by changing to append only files and creating the gob encoder once per file. If you find you&#x27;re creating a gob encoder&#x2F;decoder very often, that&#x27;s a telltale sign you&#x27;re not using it as intended.
评论 #36073777 未加载
评论 #36073843 未加载
siftricsalmost 2 years ago
This is essentially do-it-yourself etcd.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;etcd-io&#x2F;etcd">https:&#x2F;&#x2F;github.com&#x2F;etcd-io&#x2F;etcd</a>
评论 #36073691 未加载
yi_xuanalmost 2 years ago
Recently, I have been watching the course MIT6.824. This article appeared very timely :)<p>Here is another raft implementation in Go <a href="https:&#x2F;&#x2F;github.com&#x2F;eliben&#x2F;raft">https:&#x2F;&#x2F;github.com&#x2F;eliben&#x2F;raft</a>
sriram_malharalmost 2 years ago
I think that in the specific case of a key-value store (with just a get&#x2F;put API), there is a more scaleable way to get consensus than putting a KV store on Raft. Raft (and multi-paxos) present a shared log abstraction, which is good if you want to impose a single ordering (what a replicated state machine needs). But writes to different keys are order independent, and you don&#x27;t need ordering (between keys) to get a linearizable kv store. By going through raft or multi-decree paxos or VS replication, you pay a penalty for ensuring that all writes are sequentialised via the log. The penalty includes having to go through a single leader for all reads and writes, and lots of jitter when a leader fails up until the new leader becomes stable.<p>In contrast, if you simply use the equivalent of basic (single-decree) paxos per key, the writes can be leaderless. Of course, for performance reasons, each server must batch network and disk i&#x2F;o.
评论 #36079642 未加载
geospeckalmost 2 years ago
Thanks for the post!<p>Another great blog post series about implementig Raft in Go that I found is this one <a href="https:&#x2F;&#x2F;eli.thegreenplace.net&#x2F;2020&#x2F;implementing-raft-part-0-introduction&#x2F;" rel="nofollow">https:&#x2F;&#x2F;eli.thegreenplace.net&#x2F;2020&#x2F;implementing-raft-part-0-...</a>
评论 #36075270 未加载
powersetalmost 2 years ago
I highly recommend MIT open courseware 6.824. Incredibly valuable for learning distributed systems, and one of the lab assignments is implementing raft in Go. <a href="http:&#x2F;&#x2F;nil.csail.mit.edu&#x2F;6.824&#x2F;2022&#x2F;schedule.html" rel="nofollow">http:&#x2F;&#x2F;nil.csail.mit.edu&#x2F;6.824&#x2F;2022&#x2F;schedule.html</a><p>There are a ton of fascinating and potentially frustrating edge cases and gotchas to implementing raft correctly. There&#x27;s no better way to understand it than actually implementing it, and I probably never would have done it myself without these course materials.
评论 #36074397 未加载
didipalmost 2 years ago
Big fan of Phil!<p>A lot of us tinkered like him, but very few came back and write the findings nicely in an easy to read form.
评论 #36074974 未加载
leetroutalmost 2 years ago
So kinda like &quot;build your own consul&quot;
评论 #36071754 未加载
评论 #36072190 未加载
dotnwatalmost 2 years ago
epic