Skip to content
MuhammadTahaNasirPublic

About

A production-grade, high-performance in-memory key-value cache engine built in Java. Features multi-thread safety, WAL persistence, real-time analytics, and runtime eviction policies.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

Repository files navigation

⚡ ApexKV

High-Performance In-Memory Cache Engine Built in Java

Java 17+ HTML5 CSS3 JavaScript

Production-grade cache engine featuring TTL Scheduling • WAL Persistence • Runtime Eviction Policies • Pub/Sub Messaging • Web Analytics Dashboard • TCP Server


🌐 View Full Project Details & Architecture

📸 Dashboard Preview

ApexKV Dashboard

Live Web Analytics Dashboard & Cache Inspector

⚡ Why ApexKV?

Modern applications frequently encounter bottlenecks when repeatedly querying disk-backed relational databases.

ApexKV eliminates this latency by caching frequently accessed data entirely in-memory. Unlike basic hash maps, it brings enterprise-grade features such as durable persistence, multi-thread safety, intelligent eviction, and priority-queue expiration into a standalone, lightweight Java system without the overhead of heavy external dependencies.

🏗 System Architecture

ApexKV Architecture

Conceptual Architecture Diagram

Diagram Legend:
🔹 Network Layer (Left): Handles inbound connections from client applications via the Redis TCP Server (Port 6379) and Web Dashboard via HTTP/REST (Port 8080).
🔹 Core Engine (Center): The multi-threaded execution environment that parses commands and manages memory via the ConcurrentHashMap storage engine, Background TTL Scheduler, and Eviction algorithms.
🔹 Dual Persistence Layer (Right): Ensures ACID compliance by streaming commands to a Write-Ahead Log (WAL) and periodically dumping the memory state to binary snapshots.

✨ Core Features

  • 🗄️ Multi-Type Data Storage: Dynamically supports STRING, INTEGER, LIST, SET, HASH, and BINARY via the Factory Pattern.
  • ⚡ Dynamic Eviction Policies: Switch between LRU, LFU, FIFO, MRU, and RANDOM strategies at runtime without losing cached entries.
  • ⏱️ $O(\log N)$ TTL Expiration: Uses a PriorityBlockingQueue for highly efficient, deterministic key expiration and cleanup.
  • 💾 Dual Persistence (ACID): Employs both Snapshots (snapshot.cache) for state capture and Write-Ahead Logging (WAL) for crash-resilient transaction replay.
  • 📊 Real-Time Analytics Dashboard: Embedded glassmorphism web console at http://localhost:8080 for live KPI tracking, benchmark execution, and hot-key detection.
  • 🔌 Multi-Protocol Access: Interact via the embedded REST API, the interactive CLI, or standard TCP commands on port 6379.

🧠 Design Patterns

Pattern System Usage
Factory Pattern Instantiating and managing dynamic data types (ValueFactory).
Strategy Pattern Enabling hot-swappable cache eviction policies (EvictionFactory).
Observer Pattern Powering the Pub/Sub messaging and event broadcasting.
Scheduler Pattern Driving the asynchronous TTL background cleanup threads.
Singleton Pattern Centralizing shared state for Metrics, Config, and Storage engines.

📊 Performance Benchmarks

The built-in multi-threaded benchmarking tool stress-tests the system under heavy concurrent loads.

  • Concurrent Operations: 25,000+
  • Average Latency: ~1.8ms
  • Hit Rate: 96.4%+
  • Thread Safety: 0 race conditions detected during peak simulation.

🧪 Validation Results

The comprehensive CacheTestSuite continuously validates data integrity across 19/19 independent test vectors, achieving a 100% Success Rate.

  • ✅ CRUD & Types: Full coverage on all data structures.
  • ✅ TTL: Exact millisecond expiration validation.
  • ✅ Concurrency: Stress-tested with thousands of simultaneous read/writes.
  • ✅ Recovery: Verified 100% state restoration from WAL and snapshots.

📂 Repository Structure

ApexKV/
├── src/main/java/com/apexkv/
│   ├── api/            # Interfaces and REST Handlers
│   ├── benchmark/      # Load testing engine
│   ├── cli/            # Interactive terminal client
│   ├── core/           # Main CacheEngine and storage logic
│   ├── eviction/       # LRU, LFU, FIFO, MRU Strategy implementations
│   ├── expiration/     # PriorityQueue TTL Scheduler
│   ├── metrics/        # Analytics and Hot-Key tracking
│   ├── persistence/    # Write-Ahead Log (WAL) and Snapshot managers
│   ├── pubsub/         # Observer-based messaging
│   ├── server/         # TCP Socket and HTTP Dashboard servers
│   └── value/          # Data type factories and wrappers
├── build.bat           # Windows compilation script
└── run.bat             # Master execution script

🚀 Quick Start

  1. Clone the Repository
git clone https://github.com/MuhammadTahaNasir/ApexKV.git
cd ApexKV
  1. Compile the System
build.bat
  1. Launch the Engine
run.bat

(This automatically boots the Core Engine, TCP Server on 6379, and the Web Dashboard on 8080)

  1. Access the Dashboard Open your browser and navigate to: http://localhost:8080

🔮 Future Enhancements

While this project is currently a standalone cache engine, here are some advanced distributed system concepts that would serve as excellent future extensions to this architecture:

  • Consistent Hashing & Clustering: Distribute keys across multiple node rings.
  • Master/Replica Replication: High availability with real-time data propagation.
  • Bloom Filter Integration: $O(1)$ pre-check to eliminate cache-miss overhead.
  • RESTful API Upgrades: Full HTTP/JSON payload support for distributed microservices.
  • Distributed Locking: RedLock-style synchronization for distributed resources.
Developed by Muhammad Taha Nasir
GitHub • LinkedIn

About

A production-grade, high-performance in-memory key-value cache engine built in Java. Features multi-thread safety, WAL persistence, real-time analytics, and runtime eviction policies.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages