MCPcopy Index your code
hub / github.com/deventlab/d-engine

github.com/deventlab/d-engine @v0.2.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.2.4 ↗ · + Follow
4,532 symbols 17,054 edges 384 files 836 documented · 18%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

d-engine 🚀

Crates.io docs.rs codecov Static Badge CI Ask DeepWiki

d-engine is a lightweight, embeddable distributed coordination engine for Rust — strong-consistency KV, watch streams, and leader election, running inside your process.

Built with a simple vision: make distributed coordination accessible - cheap to run, simple to use. Built on a core philosophy: choose simple architectures over complex ones.

d-engine's Raft core uses a single-threaded event loop to guarantee strong consistency and strict ordering while keeping the codebase clean and performant. Production-ready Raft implementation with flexible read consistency (Linearizable/Lease-Based/Eventual) and pluggable storage backends. Start with one node, scale to a cluster when needed.


New in v0.2.4 🎉

  • Async IO Architecture: Raft event loop is fully non-blocking — WAL writes, state machine apply, and replication all run off the hot path. AppendEntries uses a persistent bidirectional stream per peer; replication is pipelined across followers.
  • Cluster Membership Streaming: EmbeddedEngine::watch_membership() / GrpcClient::watch_membership() — subscribe to real-time membership changes in both embedded and standalone modes
  • Simpler Startup: EmbeddedEngine::start(data_dir) and StandaloneEngine::run(data_dir, shutdown_rx) — no config file required for common cases
  • Jepsen Validated: 5 workloads + 6-hour soak test under combined kill/partition/pause faults — see Correctness Guarantees

Features

  • Single-Node Start: Begin with one node, scale to a 3-node cluster with zero downtime
  • EmbeddedEngine: Zero-overhead in-process access (<0.1ms latency)
  • Strong Consistency: Full Raft protocol — linearizable writes, configurable read consistency
  • Flexible Read Consistency: Three-tier model (Linearizable/Lease-Based/Eventual) per request
  • Watch API: Real-time key change notifications for configuration updates, state changes, and cluster events
  • TTL: Automatic key expiration for session management and short-lived entries
  • Pluggable Storage: Custom backends supported (RocksDB default; Sled, Raw File, or your own)
  • Modular: Feature flags (client/server) — depend only on what you need

Quick Start (Embedded Mode)

d-engine = "0.2"
use d_engine::prelude::*;
use std::time::Duration;

#[tokio::main]
async fn main() {
    let engine = EmbeddedEngine::start("./data").await.unwrap();
    engine.wait_ready(Duration::from_secs(5)).await.unwrap();

    let client = engine.client();
    client.put(b"hello".to_vec(), b"world".to_vec()).await.unwrap();
    let value = client.get_linearizable(b"hello".to_vec()).await.unwrap();

    println!("Retrieved: {}", String::from_utf8_lossy(&value.unwrap()));
    engine.stop().await.unwrap();
}

→ Full example: examples/quick-start-embedded


Integration Modes

Embedded Mode — In-Process

d-engine = "0.2"

Use when: Building Rust applications that need distributed coordination
Why: Zero-overhead (<0.1ms), single binary, zero network cost

Performance: AWS EC2 3-node cluster — 110K writes/sec, 327K linearizable reads/sec, sub-millisecond latency. See benches/reports/v0.2.4/ for details.

→ Examples:


Standalone Mode — Separate Service

d-engine = { version = "0.2", features = ["client"], default-features = false }

Use when: Application and d-engine run as separate processes
Why: Language-agnostic (Go/Python/Java/Rust), independent scaling, easier operations

Performance: 59K writes/sec, 77K linearizable reads/sec via gRPC. For maximum throughput, embedded mode is 1.9× faster on writes and 4.2× on reads. See benches/reports/v0.2.4/.

→ Example: Quick Start Standalone (Go client)


Custom Storage Backends

d-engine = { version = "0.2", features = ["server"], default-features = false }

Implement the StorageEngine and StateMachine traits for custom backends:


Performance

d-engine v0.2.4 vs etcd

d-engine vs etcd comparison

d-engine v0.2.4 vs v0.2.3

d-engine v0.2.4 vs v0.2.3 comparison

open benches/reports/

Maintainer Philosophy

d-engine has a focused roadmap maintained by a single author. We welcome bug fixes unconditionally. For feature PRs, please open an issue first — new features are evaluated against roadmap fit, not just code quality. Breaking changes before v1.0 are documented in MIGRATION_GUIDE.md.


Contributing

d-engine follows the 20/80 rule — solve real production problems, not experiments. Read CONTRIBUTING.md and open an issue before feature PRs. Bug fixes are always welcome.

Prerequisites: Rust 1.89+, Tokio runtime, Protobuf compiler

# Run all tests (fast, parallel with nextest)
make test

Follow Rust community standards (rustfmt, clippy). Write unit tests for all new features.


FAQ

Why 3 nodes for HA?
Raft requires majority quorum (N/2 + 1). A 3-node cluster tolerates 1 failure.

Can I start with 1 node?
Yes. Scale to 3 nodes later with zero downtime (see examples/single-node-expansion/).

How do I customize storage?
Implement the StorageEngine and StateMachine traits (see Custom Storage Backends above).

Production-ready?
Core Raft engine is production-grade (1000+ tests, Jepsen validated). API is stabilizing toward v1.0. Pre-1.0 versions may introduce breaking changes (documented in MIGRATION_GUIDE.md).

Migrating from etcd?
d-engine is not a drop-in replacement. See API compatibility and migration gaps before porting — lease keepalive, multi-key transactions, and auth are not supported; built-in distributed lock requires DIY via CAS.


Supported Platforms

  • Linux: x86_64, aarch64
  • macOS: x86_64, aarch64

License

Licensed under MIT or Apache 2.0, at your option.

Extension points exported contracts — how you extend this code

StorageEngine (Interface)
High-performance storage abstraction for Raft consensus Design principles: - Zero-cost abstractions through static disp [4 …
d-engine-core/src/storage/storage_engine.rs
ClientResponseExt (Interface)
(no doc) [1 implementers]
d-engine-client/src/proto/client_ext.rs
HealthMonitor (Interface)
(no doc) [1 implementers]
d-engine-server/src/network/health_monitor.rs
StateMachineBuilder (Interface)
(no doc) [5 implementers]
d-engine-core/src/storage/state_machine_test.rs
HealthCheckerApis (Interface)
(no doc) [1 implementers]
d-engine-server/src/network/health_checker.rs
StorageEngineBuilder (Interface)
(no doc) [4 implementers]
d-engine-core/src/storage/storage_engine_test.rs
StateMachine (Interface)
(no doc) [4 implementers]
d-engine-core/src/storage/state_machine.rs
RaftRoleState (Interface)
(no doc) [4 implementers]
d-engine-core/src/raft_role/role_state.rs

Core symbols most depended-on inside this repo

clone
called by 1153
d-engine-core/src/raft_role/mod.rs
send
called by 305
d-engine-core/src/maybe_clone_oneshot.rs
push
called by 282
d-engine-core/src/raft_role/buffers/batch_buffer.rs
recv
called by 253
d-engine-core/src/maybe_clone_oneshot.rs
client
called by 192
d-engine-server/src/api/embedded.rs
handle_role_event
called by 145
d-engine-core/src/raft.rs
insert
called by 137
d-engine-proto/src/exts/client_ext.rs
put
called by 134
d-engine-server/src/api/embedded_client.rs

Shape

Function 2,485
Method 1,614
Class 285
Enum 60
Struct 48
Interface 35
TypeAlias 5

Languages

Rust92%
Go8%

Modules by API surface

d-engine-proto/go/common/common.pb.go166 symbols
d-engine-proto/go/client/client_api.pb.go151 symbols
d-engine-core/src/raft_role/leader_state.rs102 symbols
d-engine-core/src/raft_test/raft_comprehensive_tests.rs95 symbols
d-engine-core/src/config/raft.rs85 symbols
d-engine-core/src/errors_test.rs68 symbols
d-engine-core/src/state_machine_handler/default_state_machine_handler_test.rs64 symbols
d-engine-core/src/raft_role/mod.rs53 symbols
d-engine-core/src/watch/manager_test.rs52 symbols
d-engine-server/src/membership/raft_membership_test.rs50 symbols
d-engine-proto/src/generated/d_engine.client.rs48 symbols
d-engine-core/src/raft_role/follower_state_test.rs48 symbols

For agents

$ claude mcp add d-engine \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact