EzRaft
A beginner-friendly Raft consensus framework built on OpenRaft.
Run your application on several machines at once, all holding the same state, so the
service survives losing some of them. That is what Raft is
for, and EzRaft reduces it to two traits: EzApp holds your state and applies requests
to it, EzStorage puts bytes on disk. Elections, replication, membership, snapshots and
the transport between machines are handled internally.
Where to draw that line is the point of the crate: EzRaft is a search for the smallest API that is still enough to build a distributed key-value store on Raft.
The way to judge an API is to build with it, so the example here is a whole working service. If a part of it feels heavier than the job deserves, that is worth reporting.
- Two methods:
apply()performs a write,read()answers a read - each with a request and a response type you choose. That is the whole application interface. - Your own types: requests, responses and state are your structs. Serde moves them between nodes; nothing here deals in byte vectors.
- Storage included:
FileStoragepersists to disk out of the box. Writing your own is three methods. - Networking included: every node serves the Raft RPCs its peers need and an HTTP API for your app. There is no transport to write.
Example
A replicated key-value service, whole. First the application: the two methods above, and the four types they carry.
/// The application *is* the replicated state: a snapshot is this struct, serialized.
Then main, which is where the cluster comes from. FileStorage is the bundled
EzStorage, so there is nothing else to implement:
/// One binary, run once per machine: `kvstore <own-addr> [addr of a node already in it]`
async
Three of those form a cluster that survives losing any one of them:
Drive it
# A write goes through the log: replicated and committed before it answers.
# null - Set answers with the value it replaced, if there was one
# A read is answered from that node's own memory: no consensus round, no log entry.
# "world" - from a node you never wrote to
Status
Experimental. The API is the thing being searched for, so it changes until the crate stabilizes. A real service built on it is the feedback the search needs most - pin the version, and read the CHANGELOG before upgrading.
Next phase: Stable API. Once the design exploration matures, EzRaft will provide a stable API with well-considered abstractions - exposing what users need while hiding unnecessary complexity.
Documentation
- Guide - run a cluster, write a service against it, and the API, configuration and HTTP endpoints that make it up
- API documentation
examples/kvstore.rs- a complete key-value service- CHANGELOG
License
Licensed under either of Apache-2.0 or MIT, at your option.