Skip to content

stejul/distribkvstore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Distributed Key-Value Store in C++ with Bully Leader Election

📌 Overview

This project is a distributed key-value (KV) store written in C++. It evolves over five phases—each improving on scalability, durability, and fault tolerance. By the final phase, it supports leader election using the Bully algorithm, enabling robust coordination across a distributed system.

Development is structured into Git branches, one per phase, allowing easy progression and experimentation.

🏗 Project Phases & Branches

Phase 1 — Basic Key-Value Store

Branch: main Implements a simple thread-safe, in-memory key-value store.

Key Features:

  • GET, SET, DEL operations
  • Command-line or API interface

Phase 2 — Logging Support

Branch: append_log Introduces write-ahead logging to persist changes and enable recovery.

Key Features:

  • Log every write operation

Phase 3 — Networking Layer

Branch: networking Adds TCP networking to serve remote clients.

Key Features:

  • TCP-based server-client model
  • Message parsing and framing
  • Concurrent client handling

Phase 4 — Replication & Refactoring

Branch: replication Enables data replication across follower nodes.

Key Features:

  • Synchronous/asynchronous replication
  • Modular server-client refactor
  • Redundancy for fault tolerance

Phase 5 — Leader Election via Bully Algorithm

Branch: leader-election Implements dynamic leader election based on node priorities.

Key Features:

  • Bully election protocol
  • Automatic failover and re-election
  • Leader coordination for write operations

🛠️ How to Build

Ensure CMake is installed and a C++17-compatible compiler is available.

mkdir build
cd build
cmake ..
cmake --build .

🚀 How to Run

For Local Operation (e.g., main, append_log)

./kvstore

For Networked Operation (e.g., networking)

Start server:

./kvstore_server

For Replicated Networked Operation (e.g., replication, leader-election)

Start server:

./kvstore_server <PORT> <PEER1>:<PORT>,<PEER2>:<PORT2>,<PEERN>:<PORTN>

Start client:

./kvstore_client <IP_ADDRESS> <PORT>

📂 Branch Overview

Phase Branch Name Description
1 main In-memory key-value store
2 append_log Adds persistent write-ahead logging
3 networking Enables client-server networking
4 replication Adds replication and modularizes codebase
5 leader-election Introduces leader election (Bully algorithm)

🔧 Technologies Used

  • C++17
  • CMake
  • POSIX Sockets
  • Multithreading (std::thread, std::mutex)
  • File I/O Logging

🧩 Potential Future Work

  • Consensus protocol integration (e.g., Raft)
  • HTTP/REST interface
  • Dynamic service discovery
  • Cluster rebalancing

🤝 Contributing

Contributions are welcome! Each phase is independently accessible via its respective branch. Ensure code is tested and adheres to existing structure.

📄 License

This project is licensed under the MIT License.

About

A journey on how I implemented a distributed Key-Value Store in C++ with Bully Leader Election

Resources

License

Stars

Watchers

Forks