| Crates.io | d-engine-server |
| lib.rs | d-engine-server |
| version | 0.2.2 |
| created_at | 2026-01-02 02:47:58.418766+00 |
| updated_at | 2026-01-14 15:06:14.684923+00 |
| description | Production-ready Raft consensus engine server and runtime |
| homepage | https://github.com/deventlab/d-engine |
| repository | https://github.com/deventlab/d-engine |
| max_upload_size | |
| id | 2017861 |
| size | 1,172,387 |
Complete Raft server with gRPC and storage - batteries included
This crate provides a complete Raft server implementation with gRPC networking, persistent storage, and cluster orchestration. It's the server runtime component of d-engine.
d-engine is a lightweight distributed coordination engine written in Rust, designed for embedding into applications that need strong consistency—the consensus layer for building reliable distributed systems.
d-engine for simpler dependency managementd-engine with features = ["server", "client"]d-engine for unified APIAdd to your Cargo.toml:
[dependencies]
d-engine-server = "0.2"
use d_engine_server::EmbeddedEngine;
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let engine = EmbeddedEngine::start_with("config.toml").await?;
engine.wait_ready(Duration::from_secs(5)).await?;
let client = engine.client();
client.put(b"key".to_vec(), b"value".to_vec()).await?;
engine.stop().await?;
Ok(())
}
use d_engine_server::StandaloneServer;
use tokio::sync::watch;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
std::env::set_var("CONFIG_PATH", "config.toml");
let (_shutdown_tx, shutdown_rx) = watch::channel(());
StandaloneServer::run(shutdown_rx).await?;
Ok(())
}
This crate provides:
┌─────────────────────────────────────────┐
│ d-engine-server │
│ │
│ ┌─────────────────────────────────┐ │
│ │ API Layer │ │
│ │ - EmbeddedEngine │ │
│ │ - StandaloneServer │ │
│ │ - LocalKvClient │ │
│ └──────────────┬──────────────────┘ │
│ │ │
│ ┌──────────────▼──────────────────┐ │
│ │ Node (Raft orchestration) │ │
│ │ - Leader election │ │
│ │ - Log replication │ │
│ │ - Membership changes │ │
│ └───────┬──────────────┬──────────┘ │
│ │ │ │
│ ┌───────▼────────┐ ┌──▼────────────┐ │
│ │ StorageEngine │ │ StateMachine │ │
│ │ (Raft logs) │ │ (KV store) │ │
│ └────────────────┘ └───────────────┘ │
│ │
│ ┌─────────────────────────────────┐ │
│ │ gRPC Services │ │
│ │ - Client RPC (read/write) │ │
│ │ - Cluster RPC (membership) │ │
│ │ - Internal RPC (replication) │ │
│ └─────────────────────────────────┘ │
└─────────────────────────────────────────┘
Simple file-based storage for development and small deployments.
use d_engine_server::{FileStorageEngine, FileStateMachine};
let storage = Arc::new(FileStorageEngine::new("./logs")?);
let sm = Arc::new(FileStateMachine::new("./sm").await?);
High-performance embedded database for production use.
[dependencies]
d-engine-server = { version = "0.2", features = ["rocksdb"] }
use d_engine_server::{RocksDBStorageEngine, RocksDBStateMachine};
let storage = Arc::new(RocksDBStorageEngine::new("./data/logs")?);
let sm = Arc::new(RocksDBStateMachine::new("./data/sm").await?);
Implement [StateMachine] and [StorageEngine] traits:
use d_engine_server::{StateMachine, StorageEngine};
struct MyStateMachine;
impl StateMachine for MyStateMachine {
// Apply committed entries to your application state
}
struct MyStorageEngine;
impl StorageEngine for MyStorageEngine {
// Persist Raft logs and metadata
}
See the Server Guide for detailed implementation instructions.
High-level API for embedding d-engine in Rust applications:
use d_engine_server::EmbeddedEngine;
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Start embedded engine with config file
let engine = EmbeddedEngine::start_with("d-engine.toml").await?;
// Wait for leader election
let leader = engine.wait_ready(Duration::from_secs(5)).await?;
println!("Leader elected: {}", leader.leader_id);
// Get zero-overhead client
let client = engine.client();
client.put(b"key".to_vec(), b"value".to_vec()).await?;
// Graceful shutdown
engine.stop().await?;
Ok(())
}
For comprehensive guides:
See working examples in the repository:
| Crate | Purpose |
|---|---|
d-engine |
Recommended - Unified API for most users |
d-engine-client |
Client library for Rust applications |
d-engine-core |
Pure Raft algorithm for custom integrations |
d-engine-proto |
Protocol definitions (foundation for all clients) |
MIT or Apache-2.0