# baidu/braft

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/baidu-braft).**

4,216 stars · 923 forks · C++ · Apache-2.0

## Links

- GitHub: https://github.com/baidu/braft
- awesome-repositories: https://awesome-repositories.com/repository/baidu-braft.md

## Topics

`distributed-consensus` `distributed-storage` `raft` `raft-consensus-algorithm` `raft-cpp` `raft-cxx` `raft-protocol` `state-machine-replication`

## Description

braft is an embeddable C++ library that implements the Raft consensus algorithm, providing a distributed consensus engine for building fault-tolerant, replicated state machines. At its core, it manages leader election, log replication, cluster membership changes, and state machine synchronization across a cluster of nodes, ensuring strong consistency and data durability even in the face of node failures.

The library distinguishes itself through a comprehensive set of mechanisms for reliable distributed coordination. It uses a randomized timeout-based leader election process with term management to ensure a single leader coordinates the cluster, and employs heartbeat-driven failure detection to trigger automatic leader failover when a node becomes unresponsive. Cluster membership changes are handled through a joint consensus protocol that prevents split-brain scenarios during dynamic node additions or removals, while quorum-based log replication guarantees that entries are committed only after reaching a majority of followers.

braft supports a replicated state machine model where each node applies the same sequence of committed log entries deterministically, ensuring identical state across the cluster. It includes snapshot-based log compaction to prevent unbounded log growth, and provides leader-routed service access for reading and writing to the replicated state machine. The library is designed for embedding directly into applications, handling automatic leader election, failover, and consistent log replication across cluster nodes.

## Tags

### DevOps & Infrastructure

- [Embedded Consensus Libraries](https://awesome-repositories.com/f/devops-infrastructure/high-availability-services/embedded-consensus-libraries.md) — Provides an embeddable Raft library that handles automatic leader election and failover within applications. ([source](https://cdn.jsdelivr.net/gh/baidu/braft@master/README.md))
- [Fault-Tolerant Coordinators](https://awesome-repositories.com/f/devops-infrastructure/cluster-coordination/fault-tolerant-coordinators.md) — Manages quorum-based consensus, heartbeat failure detection, and automatic leader failover in multi-node clusters.
- [Joint Consensus Protocols](https://awesome-repositories.com/f/devops-infrastructure/cluster-membership-protocols/joint-consensus-protocols.md) — Implements a joint consensus protocol for safe dynamic addition and removal of cluster nodes.
- [Consensus Log Replication](https://awesome-repositories.com/f/devops-infrastructure/high-availability-clusters/log-replication-strategies/consensus-log-replication.md) — Replicates log entries to a majority of followers before committing, guaranteeing consistency across failures.
- [Leader Election](https://awesome-repositories.com/f/devops-infrastructure/high-availability-systems/leader-election.md) — Implements randomized timeout-based leader election with term management to ensure a single cluster leader.
- [Heartbeat Monitors](https://awesome-repositories.com/f/devops-infrastructure/worker-node-management/heartbeat-monitors.md) — Uses periodic heartbeat messages from the leader to detect follower failures and trigger leader election.
- [Leader-Routed Request Handlers](https://awesome-repositories.com/f/devops-infrastructure/high-availability-systems/leader-election/leader-routed-request-handlers.md) — Routes all read and write requests through the cluster's elected leader node for consistent access. ([source](https://cdn.jsdelivr.net/gh/baidu/braft@master/README.md))

### Data & Databases

- [Quorum-Based Commit Protocols](https://awesome-repositories.com/f/data-databases/distributed-consensus-protocols/quorum-based-commit-protocols.md) — Implements quorum-based decision making for strong consistency guarantees across network partitions.
- [Snapshot-Based Compactions](https://awesome-repositories.com/f/data-databases/log-processing-engines/log-compaction/snapshot-based-compactions.md) — Periodically snapshots the state machine and truncates the log to prevent unbounded log growth.

### Networking & Communication

- [Raft Consensus Implementations](https://awesome-repositories.com/f/networking-communication/distributed-systems-p2p/distributed-systems-coordination/distributed-consensus-protocols/raft-consensus-implementations.md) — An embeddable library implementing the Raft consensus algorithm for log replication and state machine synchronization.

### Software Engineering & Architecture

- [Replicated State Machines](https://awesome-repositories.com/f/software-engineering-architecture/state-machine-logic/replicated-state-machines.md) — Applies the same sequence of committed log entries to a deterministic state machine on each node.
