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
Table of Contents
- Architecture: Sharded Store Design
- Core Data Model: Entry with TTL
- Sharded Storage for Scalability
- Thread-Safe GET with std::optional
- Thread-Safe SET with RAII
- TTL Expiry and Lazy Deletion
- LRU Eviction Policy
- Command-Line REPL with std::format
- Statistics and Metrics
- Performance Benchmarks
- Extension Challenges
- Phase 2 Reflection
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
- Persistence: Serialize the entire store to a binary file on SIGTERM (use
std::ofstream+std::bit_castfor POD types) - Pub/Sub: Add a
SUBSCRIBE key/PUBLISH key msgcommand usingstd::condition_variableand astd::deque<std::string>channel - Transactions: Implement
MULTI/EXECby buffering commands in astd::vector<Command>and applying atomically - 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 Concept | Used 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::chrono | TTL 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.
