Skip to content

Abhi-Jeeet/InkStore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 InkStore — High-Performance In-Memory Key-Value Store

InkStore is a high-performance, multi-threaded in-memory key-value store written in C++, designed to model real-world caching systems like Redis.

It acts as a caching layer to reduce backend latency and database load by serving frequently accessed data directly from memory.


🧠 Problem Statement

Modern backend systems face:

  • High latency due to repeated database queries
  • Performance degradation under concurrent load
  • Inefficient handling of frequently accessed data

💡 Solution

InkStore introduces an in-memory caching layer:

Client → InkStore (cache) ⚡ → Database (fallback)

This significantly improves response time and reduces database pressure.


⚙️ Features

🔹 Core

  • In-memory key-value storage (O(1) average operations)
  • TCP socket-based server
  • Multi-threaded client handling

🔹 Advanced

  • Write-Ahead Logging (WAL) for durability
  • TTL (Time-To-Live) for automatic key expiration
  • LRU eviction policy for memory management
  • Thread-safe operations using mutex synchronization

🔹 Performance

  • Custom multi-threaded benchmarking client
  • Throughput & latency measurement
  • Concurrency stress testing

🏗️ Architecture

Client (ncat / custom client)
        ↓
TCP Socket
        ↓
InkStore Server (C++)
        ↓
In-Memory Store + WAL

🧪 Benchmark Results

Threads Throughput (req/sec) Latency (ms)
1 ~7700 0.12
12 ~7300 0.13
50 ~4300 0.23
80 ~3000 0.33
100 ~3100 0.31
150 ~3170 0.31
200 ~1290 0.77

📊 Performance Visualization

🔹 Throughput vs Threads

Throughput Graph


🔹 Latency vs Threads

Latency Graph


🧠 Performance Analysis

  • Best performance observed at low concurrency (1–10 threads)

  • Throughput decreases as thread count increases due to:

    • Mutex lock contention
    • Context switching overhead
    • Socket connection overhead
  • Latency increases significantly under high concurrency

  • Demonstrates real-world limitations of shared locks in multi-threaded systems


🛠️ Tech Stack

  • Language: C++ (C++17)
  • Networking: POSIX Sockets
  • Concurrency: std::thread, mutex
  • Persistence: Write-Ahead Logging (WAL)
  • Data Structures: HashMap + Doubly Linked List (LRU)

▶️ Getting Started

🔧 Build

make

▶️ Run Server

./inkstore

⚡ Run Benchmark

make benchmark
./benchmark_app

🧪 Example Usage

Using ncat:

ncat 127.0.0.1 9090
SET name abhijeet
GET name
GETALL
DEL name

🚀 Real-World Applications

  • API response caching
  • Session storage
  • Rate limiting systems
  • High-performance backend services

🧠 Key Learnings

  • Concurrency control and synchronization
  • Performance vs scalability trade-offs
  • Memory-efficient caching strategies
  • Importance of benchmarking and profiling

⭐ Conclusion

InkStore demonstrates core backend infrastructure concepts including caching, concurrency, persistence, and performance analysis — closely mirroring real-world system design patterns used in high-performance services.


About

Designed and built a Redis-like in-memory caching system in C++ with support for concurrency, TTL expiration, LRU eviction, WAL persistence, and detailed benchmarking to analyze throughput and latency under load.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors