The author discusses his implementation of Raft, a consensus algorithm used for replicated state machines, in Go. Raft involves nodes conducting elections to pick a leader, who passes messages to followers and waits for them to commit. Once the message is committed, it is applied to a user-supplied state machine. The author builds a distributed key-value store on top of a Raft cluster, and discusses how it can be used to build a SQL database. He also provides a constructor to initialize the state for all servers in the cluster and local server state, as well as debugging and assertion helpers. The author eventually swaps encoding/gob for binary encoding, keeping track of how many entries in the log must be written, for better throughput.
https://notes.eatonphil.com/2023-05-25-raft.html