Crates.io | d-engine |
lib.rs | d-engine |
version | 0.1.3 |
created_at | 2025-04-11 08:55:49.617361+00 |
updated_at | 2025-09-03 03:55:06.323148+00 |
description | A lightweight and strongly consistent Raft consensus engine written in Rust. It is a base to build reliable and scalable distributed systems. |
homepage | https://github.com/deventlab/d-engine |
repository | https://github.com/deventlab/d-engine |
max_upload_size | |
id | 1629502 |
size | 2,158,559 |
d-engine is a lightweight and strongly consistent Raft consensus engine written in Rust. It is a base to build reliable and scalable distributed systems. Designed for resource efficiency, d-engine employs a single-threaded event-driven architecture that maximizes single CPU core performance while minimizing resource overhead. It plans to provide a production-ready implementation of the Raft consensus algorithm, with support for pluggable storage backends, observability, and runtime flexibility.
tokio
.Add d-engine to your Cargo.toml
:
[dependencies]
d-engine = "0.1.3"
use d-engine::{RaftCore, MemoryStorage, Config};
async fn main() -> Result<()> {
// Initializing Shutdown Signal
let (graceful_tx, graceful_rx) = watch::channel(());
// Build Node
let node = NodeBuilder::new(settings, graceful_rx)
.build()
.start_rpc_server()
.await
.ready()
.expect("start node failed.");
println!("Application started. Waiting for CTRL+C signal...");
// Start Node
node.run().await?;
// Listen on Shutdown Signal
// graceful_shutdown(graceful_tx, node).await?;
println!("Exiting program.");
Ok(())
}
Note: For production use, a minimum of 3 nodes is required to ensure fault tolerance.
sequenceDiagram
participant Client
participant Leader
participant Raft_Log as Raft Log
participant Followers
participant State_Machine as State Machine
Client->>Leader: Propose("SET key=value")
Leader->>Raft_Log: Append Entry (Uncommitted)
Leader->>Followers: Replicate via AppendEntries RPC
Followers-->>Leader: Acknowledge Receipt
Leader->>Raft_Log: Mark Entry Committed
Leader->>State_Machine: Apply Committed Entry
State_Machine-->>Client: Return Result
Important Notes
open benches/reports/
d-engine includes Jepsen tests to validate linearizability and fault-tolerance under partitions and crashes.
To run Jepsen tests (requires Docker & Leiningen): See examples/three-nodes-cluster/docker/jepsen/README.md for full instructions.
# Build and test
cargo test --all-features
cargo clippy --all-targets --all-features -- -D warnings
cargo fmt --all -- --check
Follow Rust community standards (rustfmt, clippy). Write unit tests for all new features.
Why are 3 nodes required? Raft requires a majority quorum (N/2 + 1) to achieve consensus. A 3-node cluster can tolerate 1 node failure.
How do I customize storage? Implement the Storage trait and pass it to RaftCore::new.
Is d-engine production-ready? The current release (v0.0.1) focuses on correctness and reliability. Performance optimizations are planned for future releases.
d-eninge is licensed under the terms of the MIT License or the Apache License 2.0, at your choosing.