Skip to content

About

Replicated key-value storage engine with Raft, WAL-backed LSM trees, MVCC transactions, gRPC, and Rust YCSB benchmarks

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Distributed Storage Engine

A replicated key-value database built around a real Raft state machine, a WAL-backed LSM write path, MVCC, serializable transactions, and a gRPC API. The server is written in Go; the contention-aware YCSB benchmark is written in Rust.

The repository runs as a five-voter cluster, survives leader failure, supports both leveled and size-tiered compaction, and records benchmark output as JSON. It is intentionally a single Raft group rather than a pretend “distributed” wrapper around five independent processes.

Measured results

Five local processes, synchronous storage WAL writes enabled, 256-byte values, 128 clients, 90% of requests targeting the hottest 1% of keys:

Workload Mix Operations Throughput p50 p99 Errors
YCSB A 50% read / 50% write 50,000 1,835 ops/s 86.1 ms 161.7 ms 0
YCSB B 95% read / 5% write 50,000 12,234 ops/s 1.9 ms 117.0 ms 0
YCSB C 100% read 100,000 27,144 ops/s 2.9 ms 40.3 ms 0

These are loopback measurements from June 24, 2026, not cloud claims. Raw reports are in bench/results. Workload F exercises transactional read-modify-write and reports aborts separately from transport errors.

Architecture

flowchart LR
    C["gRPC client"] --> L["Leader API"]
    L --> B["Group commit"]
    B --> R["Raft log"]
    R --> N1["Node 1 FSM"]
    R --> N2["Node 2 FSM"]
    R --> N3["Node 3 FSM"]
    R --> N4["Node 4 FSM"]
    R --> N5["Node 5 FSM"]
    N1 --> W["CRC WAL"]
    W --> M["Versioned memtable"]
    M --> S0["L0 SSTables"]
    S0 --> C1["Leveled or size-tiered compaction"]
Loading

Each accepted mutation is committed by a Raft majority before it reaches the LSM state machine. The state machine appends a length-delimited, CRC32-protected WAL record before updating the memtable. Flushes create immutable, sorted SSTables with Bloom filters and an atomic manifest update.

Concurrent writes are grouped into Raft entries of up to 256 mutations. This preserves durability while amortizing Raft-log and WAL fsync costs.

Correctness model

  • Writes and membership changes are leader-only and majority replicated.
  • Point reads use a quorum-verified leader lease and an FSM barrier. The 50 ms lease is well below Raft's election timeout and lets concurrent reads share one verification.
  • Transactions read from a pinned MVCC snapshot and buffer their writes.
  • Commit validates every observed key against its latest version inside the replicated state machine. Blind writes also record their snapshot version.
  • Transactional range scans install a global sequence fence. It is conservative—it may abort on an unrelated concurrent write—but prevents phantoms and keeps range transactions serializable.
  • Compaction retains versions newer than the oldest pinned snapshot plus the first visible version at that snapshot.
  • Raft snapshots export and restore the complete MVCC state.

Run it

Requirements: Go 1.23+, Rust stable, and Protocol Buffers. Docker is optional.

Start five local nodes:

./scripts/local-cluster.sh

Or use Docker Compose:

docker compose up -d --build node1 node2 node3 node4 node5

Use the CLI against the leader:

go run ./cmd/dsectl put account:1 100
go run ./cmd/dsectl get account:1
go run ./cmd/dsectl scan account: account:~ 100
go run ./cmd/dsectl txn get:account put:account:125
go run ./cmd/dsectl stats

The transaction CLI uses : as its operation delimiter, so its demonstration keys do not contain colons.

Run the failure test. It forms five voters, writes data, kills the original leader, waits for a new election, and verifies the data through the new leader:

make smoke

Benchmark

The Rust driver supports YCSB A, B, C, and F plus a configurable hot set:

cd bench
cargo run --release -- \
  --endpoint http://127.0.0.1:7001 \
  --workload b \
  --operations 50000 \
  --concurrency 128 \
  --keyspace 10000 \
  --value-size 256 \
  --hotset-fraction 0.01 \
  --hot-operation-fraction 0.90 \
  --load \
  --output results/run.json

The report includes successful operations, conflicts, errors, throughput, and min/p50/p95/p99/max latency.

Configuration

Important server flags:

Flag Default Purpose
-id required Stable Raft server ID
-data-dir ./data Raft, WAL, manifest, and SSTable storage
-grpc-bind 127.0.0.1:7001 Client API address
-raft-bind 127.0.0.1:8001 Raft transport listener
-raft-advertise Raft bind address Peer-reachable Raft address
-bootstrap false Create the first voter
-join empty Existing leader's gRPC address
-memtable-mb 4 Flush threshold
-compaction leveled leveled or size-tiered
-sync-writes true Fsync every LSM WAL batch

Development

make generate
make lint
make test-race
make smoke

CI runs Go race tests, go vet, Rust formatting, Clippy with warnings denied, Rust tests, the five-node smoke test, and a container build.

Deliberate limits

This is a focused storage-engine implementation, not a production service:

  • one Raft group; no range sharding or rebalancing;
  • SSTable contents are loaded into memory on open, while files remain the durable source of truth;
  • static client endpoint discovery after leader changes;
  • full-state Raft snapshots rather than incremental snapshots;
  • no TLS, authentication, quotas, or online backup protocol.

Those boundaries are explicit so the implemented guarantees are easy to audit.

About

Replicated key-value storage engine with Raft, WAL-backed LSM trees, MVCC transactions, gRPC, and Rust YCSB benchmarks

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages