r/programming • u/Fantastic_Wave1982 • 1d ago
Data Replication In Distributed Systems | Implement Raft From Scratch
https://sushantdhiman.dev/blog/raft/
12
Upvotes
r/programming • u/Fantastic_Wave1982 • 1d ago
1
u/AnkerSOLIX-Support 1d ago
Raft's election and log replication pseudocode translate pretty well to code. For folks who've run it in prod, what took more work: getting persistence right or catching up a follower from a snapshot after it'd been down for hours?
1
u/yeeStwind 10h ago
connectToPeer busy-spins on conn.GetState() with no sleep or WaitForStateChange, so it burns a core while waiting, and main blocks forever if a peer never comes up. gRPC has WaitForStateChange for exactly that. One dead node currently means no node finishes startup.
1
u/shipitcodes 7h ago
One persistence detail that bites a lot of from-scratch Raft implementations: currentTerm and votedFor have to be fsynced before you reply to a RequestVote or AppendEntries, not just written to a file. If a node votes, crashes, and comes back without that vote on disk, it can vote again in the same term and you can end up with two leaders. The log entries need the same treatment before a follower acks them.