C++Projects

Project: Building a High-Performance In-Memory Key-Value Store (TopicKV) — Phase 2 Capstone

TT
TopicTrick Team
Project: Building a High-Performance In-Memory Key-Value Store (TopicKV) — Phase 2 Capstone

Project: Building a High-Performance In-Memory Key-Value Store (TopicKV) — Phase 2 Capstone


Table of Contents


Architecture: Sharded Store Design

To avoid a single global lock bottlenecking all operations, TopicKV uses sharding — 16 independent sub-maps each with their own mutex:

mermaid

Core Data Model: Entry with TTL

cpp

Sharded Storage for Scalability

cpp

Thread-Safe GET with std::optional

cpp

Thread-Safe SET with RAII

cpp

TTL Expiry and Lazy Deletion

cpp

LRU Eviction Policy

cpp

Command-Line REPL with std::format

cpp

Extension Challenges

  1. Persistence: Serialize the entire store to a binary file on SIGTERM (use std::ofstream + std::bit_cast for POD types)
  2. Pub/Sub: Add a SUBSCRIBE key / PUBLISH key msg command using std::condition_variable and a std::deque<std::string> channel
  3. Transactions: Implement MULTI / EXEC by buffering commands in a std::vector<Command> and applying atomically
  4. Network interface: Wrap the store in a TCP server using std::jthread (from Module 14) — one thread per connection using the REPL dispatch logic

Phase 2 Reflection

Phase 2 ConceptUsed In TopicKV
std::unordered_map (Module 10)Core key-value storage per shard
std::shared_ptr (Module 3)Entry value — snapshot safety
std::shared_mutex (Module 14)Concurrent reader/writer safety
std::optional (Module 6)GET return type — explicit "not found"
std::chronoTTL timestamps, expiry comparison
RAII locks (Module 8)shared_lock / unique_lock auto-release
std::atomic (Module 14)Lock-free statistics counters
std::ranges::min_element (Module 15)LRU eviction algorithm

Proceed to Phase 3: Inheritance & Composition →


Part of the C++ Mastery Course — 30 modules from modern C++ basics to expert systems engineering.