Skip to content

neelsani/kv-store

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kv-store

Distributed key-value store in C++17. Built to understand how systems like Redis and etcd work under the hood — consistent hashing, gossip-based failure detection, Raft consensus, and async I/O via io_uring.

Architecture

  • Server — io_uring event loop feeds a lock-free thread pool; text protocol parsed with string_view (zero-copy)
  • Storage — 16-shard hash table backed by a custom slab allocator (mmap, per-size-class free lists)
  • Cluster — consistent hashing ring (CRC32, virtual nodes) for key distribution across nodes
  • Membership — UDP gossip with ALIVE/SUSPECT/DEAD state machine; failure detection without a central coordinator
  • Consensus — Raft for strong-consistency writes: leader election, log replication, WAL-persisted to disk
  • Consistency levels — ONE, QUORUM, ALL, STRONG (Raft path)

Build

Requires Linux 5.11+ (for io_uring), liburing, CMake 3.16+, GCC 10+ or Clang 12+.

apt install liburing-dev
cmake -B build && make -C build -j$(nproc)

Usage

./build/kvstore --port 6379

echo "SET foo bar" | nc localhost 6379
echo "GET foo"     | nc localhost 6379

Start a 6-node cluster:

./scripts/run_cluster.sh

Benchmarks

# kvstore vs redis side by side
./scripts/run_bench_compare.sh

# memory comparison
./scripts/measure_memory.sh

# perf flamegraph (requires FlameGraph + sudo sysctl -w kernel.perf_event_paranoid=1)
./scripts/run_perf.sh ~/FlameGraph

Single-node results (x86 dev server, 200k ops, 64b values):

system ops/sec p50 p99
kvstore 23,350 42.5 µs 50.3 µs
redis 12,556 63.8 µs 141.1 µs

Memory at 100k keys, 64b values:

system RSS bytes/key
kvstore 27 MB 281
redis 14 MB 139

About

a performant distributed key value store written in c++

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors