"Entropy is inevitable. Data loss is not."
Chronos is a persistent, concurrent, and high-performance Key-Value store built from scratch in Rust. It implements a Log-Structured Merge-Tree (LSM) architecture similar to RocksDB or LevelDB, coupled with a custom TCP Protocol for remote access.
Designed as an educational deep-dive into systems engineering, Chronos bridges the gap between simple in-memory hashmaps and production-grade databases like Redis.
- Hybrid Storage Engine: Uses an in-memory
MemTable(HashMap) for nanosecond-latency reads and disk-basedSSTablesfor long-term storage. - Write-Ahead Log (WAL): Guarantees Durability (ACID). Every write is appended to a log file before acknowledgement. If the server crashes, Chronos replays the WAL upon restart to restore the state (0% Data Loss).
- Tombstone Deletion: High-efficiency
DELcommand implementation that uses memory tombstones to mark records as deleted without triggering expensive disk re-writes.
- Multithreaded Server: Handles concurrent TCP connections using thread spawning and safe memory sharing.
- Lock-Free Reads: Implements
Arc<RwLock<T>>to allow multiple simultaneous readers without blocking. Writers only block when absolutely necessary. - Graceful Shutdown: Intercepts
SIGINT(Ctrl+C) signals to safely block new connections, flush memory buffers to disk, and close TCP sockets without data corruption.
- Crash Recovery: Automatic "Rehydration" mechanism restores database state from disk on boot.
- Live Compaction: In-memory garbage collection to prune tombstones and duplicated logs, optimizing the read path.
The system is composed of three distinct layers, completely decoupled:
- The Interface (Network Layer -
server.rs): Raw TCP Sockets and Multithreading. - The Parser (Translation Layer -
parser.rs): Zero-copy parsing transforming raw bytes into strict Command Enums. - The Core (Storage Layer -
engine.rs): Volatile RAM storage and Append-only persistence file (chronos.db).
git clone [https://github.com/baltasarblanco/chronos_lsm.git](https://github.com/baltasarblanco/chronos_lsm.git)
cd chronos_lsmcargo runExpected Output:
🚀 CHRONOS SERVER LISTO Y ESCUCHANDO EN TCP 127.0.0.1:8080Chronos includes its own built-in terminal client (similar to redis-cli). Open a second terminal and run:
cargo run --bin clientchronos> SET user:101 {"name": "Venom", "role": "Symbiote"}
OK
chronos> GET user:101
{"name": "Venom", "role": "Symbiote"}
chronos> DEL user:101
OK_DELETED
chronos> COMPACT
OK_COMPACTED
Tests performed on local hardware via a single sequential TCP connection. Measured using 10,000 consecutive operations.
| Operation | Mechanism | Throughput (Sequential) | Latency | Outcome |
|---|---|---|---|---|
Write (SET) |
RwLock (Write) + Disk Append |
~10,500 ops/sec | ~0.09 ms/op | Atomic Safety |
Read (GET) |
RwLock (Read) |
~15,000 ops/sec | ~0.06 ms/op | Non-Blocking |
Delete (DEL) |
Tombstone Injection | O(1) in WAL | - | Zero Disk Rewrite |
(Note: These metrics reflect raw sequential round-trips. Concurrent throughput via thread-pooling is significantly higher).
Baltasar Blanco - Systems Engineer / Rustacean Building infrastructure from the atom up.