About this project
hashicorp/raft is a Go library that implements the Raft consensus algorithm, providing a foundation for building replicated state machines in distributed systems. The library manages a replicated log and integrates with a finite state machine (FSM) abstraction to maintain consistent state across multiple nodes.
Key capabilities include:
- **Leader Election**: Nodes transition between follower, candidate, and leader states. Followers self-promote to candidates if no entries are received for a timeout period, then request votes from peers. A candidate receiving a quorum of votes becomes the leader.
- **Log Replication**: The leader appends new log entries (opaque binary blobs) to durable storage and replicates them to a quorum of followers. Once committed, entries are applied to the FSM.
- **Automatic Snapshotting**: To prevent unbounded log growth, Raft automatically snapshots the current FSM state and compacts the log, removing entries that have already been applied.
- **Dynamic Peer Management**: The library supports adding and removing nodes from the cluster as long as a quorum is available.
- **Storage Backends**: The primary backend MDBStore is in a separate repository (raft-mdb), and a pure Go backend using BoltDB is available (raft-boltdb). Both can serve as LogStore and StableStore implementations.
- **Metrics Emission**: Supports metrics via armon/go-metrics (default) or hashicorp/go-metrics (via build tag), with a migration path from the deprecated armon library.
The library requires Go 1.16+ and is licensed under MPL 2.0. It is based on the Raft paper 'In Search of an Understandable Consensus Algorithm' and is comparable in performance to Paxos, with log commit latency bounded by disk I/O and network round trips to half the cluster.
Recommended cluster sizes are 3 or 5 nodes, which tolerate 1 or 2 node failures respectively while maximizing availability. The library is used by HashiCorp products such as Consul and Nomad for distributed coordination.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.