- Leader election — randomized-timeout election with term and vote safety and pre-vote disruption protection; one leader per term
- Log replication — batched append-entries with per-follower progress, optimistic pipelining, conflict-hint backtracking, and commit on a quorum
- Deterministic core — the state machine is pure and step-driven, so the whole protocol is testable without time or I/O
- Pluggable transport —
RaftTransporttrait; in-memory for tests, real net for production - Pluggable log store —
RaftLogtrait;wal-db-backedWalLogunder thepersistencefeature - Crash recovery — term, vote, and log persisted before each RPC; a restarted node recovers and rejoins without violating safety
- Snapshotting — install-snapshot for log compaction and fast follower catch-up, driven by a snapshot-policy hint
- Typed framing —
pack-iowire encoding for messages under theframingfeature - Membership changes — single-server add/remove with safe sequencing, non-voting learners with promotion, and leadership transfer
- Linearizable reads — ReadIndex reads that reflect every committed write, confirmed against a quorum, with no log append
Installation
[]
= "1.0"
# Optional features:
= { = "1.0", = ["persistence"] } # durable wal-db-backed `WalLog`
= { = "1.0", = ["framing"] } # pack-io wire framing for messages
Quick Start
A node is a deterministic state machine. You hand it events with step and it
hands back actions to carry out. The single-node path needs nothing else — no
transport, no storage to wire up:
use ;
// One node, no peers: it reaches quorum (itself) the moment it times out.
let mut node = new;
// Drive logical ticks until it elects itself leader.
while !node.is_leader
assert_eq!;
// A leader commits its own proposals immediately (quorum of one).
for action in node.step.unwrap
assert_eq!;
A multi-node cluster works the same way: you route each Action::Send to the
target node's step through a transport of your choosing, and feed every node
logical ticks. The protocol is sans-I/O — when to tick and how to deliver
messages are yours to decide, which is what makes the whole thing testable
without a clock or a network.
Runnable examples show each path end to end:
Status
1.0 — stable. The protocol is complete: election (with pre-vote
disruption protection), log replication, durable crash recovery, snapshots,
single-server membership changes with non-voting learners, leadership transfer,
and linearizable reads (the ReadIndex protocol). A kitchen-sink adversarial test
suite drives clusters through combined partitions, message loss/reorder/duplication,
membership churn, and snapshotting, and asserts all five Raft safety properties
(Election Safety, Leader Append-Only, Log Matching, Leader Completeness, State
Machine Safety) continuously over sustained runs; a companion suite drives a
replicated key-value store to identical state on every node — and serves stale-free
linearizable reads — under the same faults; and the decode path is fuzzed. The public
API, the wire format, and the durable log format are frozen and will not change
incompatibly before 2.0 — see the normative
docs/PROTOCOL.md. The full public
surface is documented in docs/API.md, with
performance baselines in docs/BENCHMARKS.md.
Where It Fits
raft-io is the consensus engine. It is consumed by:
wal-db— durable Raft log persistence (underpersistence)pack-io— typed RPC message framing (underframing)- Hive DB — cluster coordination and replicated metadata
It stays foreign-compatible: usable standalone in any system that needs replicated, fault-tolerant state.
Cross-Platform Support
Tier 1 Support:
- Linux (x86_64, aarch64)
- macOS (x86_64, Apple Silicon)
- Windows (x86_64)
Behavior is verified on each target by the CI matrix.
Contributing
Before opening a PR, cargo fmt --all, cargo clippy --all-targets --all-features -- -D warnings, and cargo test --all-features must be clean. Hot-path changes require a criterion benchmark; correctness-critical paths require property and/or loom tests.