VeloCache: A high-performance, Redis-compatible in-memory key-value store built from scratch in C++20 using kqueue and async I/O
Hi everyone,
I wanted to share a systems project I’ve been building solo: **VeloCache**. It’s a high-performance, Redis-compatible in-memory key-value store written from scratch in C++20, specifically optimized for macOS/BSD using native `kqueue`.
# Key Technical Architecture:
* **Asynchronous Networking:** A single `kqueue` event loop handles non-blocking TCP sockets, supporting pipelining and fragmented frames without spawning a thread per client.
* **Non-blocking Storage Thread:** The core storage engine, AOF logging, and replication updates are handled by a dedicated FIFO `BackgroundWorker` thread. Communication between the network loop and storage is done via a non-blocking `socketpair`.
* **Efficient TTL Indexing:** Deadlines are tracked via a `std::multimap<std::int64_t, std::string>`, ordered by absolute deadline. Erasing by iterator prevents O(N) database scans, giving amortized O(1) performance.
* **Durability:** Implements AOF persistence with 64-bit FNV-1a checksums and atomic snapshot installations (`mkstemp` \+ `rename`).
* **Asynchronous Replication:** Master/slave topology supporting `SYNC` streams, sequence validation, and explicit loading states.
I also wrote a zero-dependency TypeScript client using only the native Node.js `net` module for integration testing.
The project puts a lot of focus on POSIX resource boundaries, backpressure control (128 MiB / 1024 operations max queue budget), and edge-case test suites (covering everything from mid-flight replication drops to simulated slow-disk `fsync` injection via an interposition library).
The repository has a fully configured macOS CI pipeline. I would absolutely love to get some **brutal code review**, architecture critiques, or tips on performance optimization from the systems engineers here!
**Repo Link:** [https://github.com/geamnegru/VeloCache](https://github.com/geamnegru/VeloCache)
Thanks for reading!
https://redd.it/1x0kw4o
@r_cpp
Post #25823
8