
Implementing Raft: Part 2: Commands and Log Replication - ingve
https://eli.thegreenplace.net/2020/implementing-raft-part-2-commands-and-log-replication/
======
manigandham
Go has a nice set of polished libraries now for distributed computing
(hashicorp/raft, etc) that makes it easy to start new projects. I wish other
languages also had as many, might have to start porting.

~~~
dnautics
Raft is incredibly easy to write correctly, with tests, since basically
everything you need is in figure 2. I've done it once, but then lost all of
the code because I got mugged, my computer was stolen, and I forgot to make a
github repo, and am rebuilding it currently (current one I'm doing clocks at
about 700 SLOC, including tests and it's about 3/4 done).

~~~
rubiquity
Raft is not easy to implement. People think it is. But that’s only because
they have implemented the happy paths, which are hard enough to get right as
it is.

~~~
monadic2
Could you explain which parts you found difficult to implement?

~~~
gozzoo
The alternative to the happy paths would be all unexptecd things that might
happen. They would be easy to implement only if we can forsee them. I think
the diffuculty comes from our limited abiliyt to to predict all situations
where things may go wrong.

~~~
gozzoo
A classic example of this is when in 2006 it was discovered that nearly all
implementations of binary search and mergsort are broken - more than 50 years
after these algorithms where invented, and after they've been implemented
thousands of times by the brghtest minds in computer science.

Joshua Bloch (of the Java fame) bloged about this [1] and here is the main
take-away:

> The key lesson was to carefully consider the invariants in your programs.

[1] [https://ai.googleblog.com/2006/06/extra-extra-read-all-
about...](https://ai.googleblog.com/2006/06/extra-extra-read-all-about-it-
nearly.html)

------
beders
Wouldn't it be nice if this was actually part of the OS networking stack?

Wouldn't that make it easier to write correct (for some form of correctness)
distributed applications, leaving the messy details to a proven lower-level
stack?

~~~
antoinealb
I wrote my master thesis on putting raft inside the RPC layer exactly for that
reason. We arrived at the conclusion that this was indeed a very good way to
easily provide distributed consensus to the application layer.

~~~
nujabe
Interesting, do you mind sharing your thesis?

~~~
antoinealb
Here it is: [https://github.com/antoinealb/master-
thesis/blob/master/thes...](https://github.com/antoinealb/master-
thesis/blob/master/thesis.pdf)

Happy to discuss it in more details as well :)

------
wpietri
Ah, nice. My first introduction to systems with replayable command logs at
their heart was Prevalyer, and it really changed the way I think about system
design for the better. I'm excited to try this out.

