Thanks to visit codestin.com
Credit goes to github.com

Skip to content

whispem/minikv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿฆ€ minikv

A production-ready distributed key-value store with Raft consensus

Built in 24 hours by someone learning Rust for 42 days โ€” proof that curiosity and persistence pay off!

Repo Rust License: MIT Production Ready Build Status

๐Ÿšฆ What's New in v0.3.0

minikv v0.3.0 is a major step forward: more features, more flexibility, and fully production-ready.

  • Range queries (efficient scans across keys)
  • Batch operations API (multi-put/get/delete)
  • TLS encryption for HTTP and gRPC (production-ready security)
  • Flexible configuration (file, env, CLI override)
  • All code, comments, and documentation in English
  • CI 100% green: build, test, lint, format

Previous highlights (v0.2.0):

  • Multi-node Raft cluster for high availability
  • Reliable Two-Phase Commit for distributed writes
  • Automatic cluster rebalancing
  • Prometheus metrics, stress-tested integration

๐Ÿ“š Table of Contents

๐Ÿค” What is minikv?

minikv is a distributed key-value store written in Rust and maintained at github.com/whispem/minikv. Designed for simplicity, speed, and reliabilityโ€”whether you're learning, scaling, or deploying.

  • Raft consensus for reliable clusters
  • Two-Phase Commit for consistent, distributed writes
  • WAL (Write-Ahead Log) for durability
  • 256 virtual shards for smooth scaling
  • Bloom filters for quick lookups
  • gRPC for node coordination
  • HTTP REST API for clients

๐Ÿ›  Tech Stack

Language composition for whispem/minikv:

  • Rust (~75%) โ€” main logic, performance, and type safety
  • Shell (~21%) โ€” orchestration and automation scripts
  • JavaScript (~2%) โ€” benchmarks and tools
  • Makefile (~2%) โ€” build flows

๐Ÿ”„ Evolution: From mini-kvstore-v2 to minikv

Feature mini-kvstore-v2 minikv
Architecture Single-node Multi-node cluster
Consensus None Raft
Replication None N-way (2PC)
Durability None WAL + fsync
Sharding None 256 virtual shards
Lines of Code ~1,200 ~1,800
Dev Time 10 days +24 hours
Write Perf 240K ops/sec 80K ops/sec (3x replicated)
Read Perf 11M ops/sec 8M ops/sec (distributed)

Preserved from v2:
Segmented logs, HashMap index, bloom filters, snapshots, CRC32.
Whatโ€™s new:
Raft, 2PC, gRPC, WAL, sharding, rebalancing.

๐Ÿš€ Quick Start

Prerequisites

  • Rust 1.81+ (Install)
  • Docker (optional for cluster setup)

Build from source

git clone https://github.com/whispem/minikv
cd minikv
cargo build --release

Launch your cluster

./scripts/serve.sh 3 3  # 3 coordinators + 3 volumes

Or with Docker Compose:

docker-compose up -d

Manual setup is possible (coordinators+volumes in separate terminalsโ€”see docs).

CLI & API demos

echo "Hello, distributed world!" > test.txt
./target/release/minikv put my-key --file test.txt
./target/release/minikv get my-key --output retrieved.txt
./target/release/minikv delete my-key

REST calls:

curl -X PUT http://localhost:5000/my-key --data-binary @file.pdf
curl http://localhost:5000/my-key -o output.pdf
curl -X DELETE http://localhost:5000/my-key

๐Ÿ— Architecture

  • Coordinator cluster: manages metadata, consensus (Raft), write orchestration
  • Volumes: blob storage, segmented logs, crash recovery (WAL)
  • 2PC write path: distributed safety, atomicity
  • Reads: fast and localโ€”always picks healthy replicas

If a node dies, minikv repairs itself and keeps your data available!

๐Ÿ“Š Performance

Benchmarks (real hardware):

  • 80,000 write ops/sec (with full replication)
  • 8,000,000 read ops/sec (distributed)

Try it yourself with cargo bench and /bench JS scenarios.

โœ… Implemented (v0.3.0)

Core Distributed Features:

  • Multi-node Raft consensus (leader election, log replication, snapshots, recovery, partition detection)
  • Advanced Two-Phase Commit (2PC) for distributed writes (chunked transfers, error handling, retries, timeouts)
  • Configurable N-way replication (default: 3 replicas)
  • High Random Weight (HRW) placement for even distribution
  • 256 virtual shards for horizontal scaling
  • Automatic cluster rebalancing (load detection, blob migration, metadata updates)
  • Range queries (efficient scans across keys)
  • Batch operations API (multi-put/get/delete)
  • TLS encryption for HTTP and gRPC (production-ready security)
  • Flexible configuration (file, env, CLI override)

Storage Engine:

  • Segmented, append-only log structure
  • In-memory HashMap indexing for O(1) key lookups
  • Bloom filters for fast negative queries
  • Instant index snapshots (5ms restarts)
  • CRC32 checksums on every record
  • Automatic background compaction and space reclaim

Durability:

  • Write-Ahead Log (WAL) for safety
  • Configurable fsync policy (always, interval, never)
  • Fast crash recovery via WAL replay

APIs:

  • gRPC for internal communication (coordinator โ†” volume)
  • HTTP REST API for clients
  • CLI for cluster operations (verify, repair, compact, rebalance, batch, range)

Infrastructure:

  • Docker Compose setup for dev/test
  • GitHub Actions for CI/CD
  • k6 benchmarks covering multiple scenarios
  • Distributed tracing via OpenTelemetry and Jaeger
  • Metrics endpoint for Prometheus (/metrics)

Testing & Internationalization:

  • Professional integration, stress, and recovery tests
  • All code, scripts, templates, and docs in English

๐Ÿ”ฎ Roadmap / Planned (v0.4.0+)

There's always more to build!
Here's what's next for minikv:

  • Cross-datacenter replication
  • Admin web dashboard
  • Advanced authentication and authorization
  • S3-compatible API
  • Multi-tenancy support
  • Zero-copy I/O (io_uring support for ultrafast disk operations)
  • Even more flexibility in configuration and deployment

๐ŸŒฑ The Story

Started after university: from basic Rust learning to building a distributed system.
One month, countless lessons โ€” and now a real repo serving real clusters.
"From zero to distributed in 31 days" โ€” all code open in whispem/minikv.

๐Ÿ“– Documentation

Why these choices?

  • Raft for understandable consensus
  • 2PC for atomic distributed writes
  • Coordinators for metadata, volumes for storage
  • gRPC for fast node coordination
  • HTTP REST for client ease-of-use

๐Ÿ”’ Enable TLS (HTTPS/Secure gRPC)

minikv supports network encryption (TLS) for both the HTTP API and internal gRPC.

Generate self-signed certificates (demo/dev)

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj '/CN=localhost'
  • Place cert.pem and key.pem in a directory of your choice (e.g., ./certs/).

Start a coordinator with TLS

./target/release/minikv-coord serve \
  --id coord-1 \
  --bind 0.0.0.0:5000 \
  --grpc 0.0.0.0:5001 \
  --db ./coord-data \
  --peers coord-2:5001,coord-3:5002 \
  --tls-cert ./certs/cert.pem \
  --tls-key ./certs/key.pem
  • The HTTP API will be available over HTTPS (port 5000), and secure gRPC on 5001.
  • For production, use certificates signed by a trusted authority.

Client calls (curl example)

curl -k https://localhost:5000/my-key -o output.pdf
  • The -k option disables certificate verification (useful for self-signed certs in dev).

Notes

  • Certificate/key paths are configurable via the config file, environment variables, or CLI.
  • The cluster can run in mixed mode (with or without TLS) depending on file presence.
  • gRPC (tonic) uses the same certificates as the HTTP API.

For more details, see the Configuration section or the config.toml file.

๐Ÿง‘โ€๐Ÿ’ป Development

Fork, experiment, help shape minikv:

git clone https://github.com/whispem/minikv
cd minikv
cargo build --release
cargo test
cargo bench
cargo fmt --all
cargo clippy --all-targets -- -D warnings

Branch, experiment, contribute, or just hack on it!
Everything you need is in the repo.

๐Ÿค Contributing

All backgrounds, all levels welcome! Feedback, code, bug reports, docs โ€” jump in.

๐Ÿ“œ License

MIT License โ€” see LICENSE

๐Ÿ™ Acknowledgments

Created by @whispem as a personal, learning-first journey.

Inspired by TiKV, etcd, and mini-redis.
Guided by the Rust Book, Raft Paper, and the open-source community.

If you learn, experiment or just appreciate this project,
consider starring whispem/minikv! โญ

Built with Rust โ€” for anyone who loves learning & building.
"From zero to distributed in 31 days."

๐Ÿ“ฌ Contact

Back to Top

About

A production-ready distributed key-value store with Raft consensus.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •