gitmyhub

raft

Go ★ 9.0k updated 9d ago

Golang implementation of the Raft consensus protocol

A Go library that implements the Raft consensus protocol, used to keep a cluster of servers in sync even when some fail. Powers HashiCorp products like Consul.

GoBoltDBLMDBgRPCsetup: hardcomplexity 4/5

This is a Go library from HashiCorp that implements the Raft consensus protocol. Consensus, in computing, means getting a group of servers to agree on a shared record of events, even when some servers fail or go offline. This library is the building block that powers HashiCorp's own products like Consul, and it is used broadly in distributed systems where multiple machines need to stay in sync.

The way it works: a group of servers (called a cluster) elects one leader. All writes go to the leader, which records each change and sends copies to the other servers (followers). Once enough followers confirm they received the entry, the change is considered committed and takes effect. If the leader disappears, the remaining servers hold an election and pick a new one. A cluster of three servers can survive one failure; five servers can survive two.

The library manages its own log storage, periodically compresses old history into snapshots so disk space does not grow forever, and handles servers joining or leaving the cluster. It does not dictate what your application does with those committed entries; instead, it calls into a state machine interface that you implement, so the actual business logic stays in your code.

For storage backends, the library ships without a built-in database layer. HashiCorp maintains two separate companion libraries: one based on BoltDB (pure Go, no C dependencies) and one based on LMDB, which is the recommended choice for production. Community examples on GitHub show how to pair the library with gRPC or build a distributed key-value store on top of it.

This is a lower-level building block aimed at developers writing distributed systems in Go, not an end-user application. If you need servers to agree on shared state reliably, this library provides the coordination mechanism.

Where it fits