NGDB - High-Performance RocksDB Wrapper
A thread-safe, synchronous RocksDB wrapper for Rust that provides a clean, type-safe API with zero async overhead. NGDB abstracts away RocksDB complexity, offering ACID transactions, automatic backups, and distributed replication infrastructure.
Features
- ๐ Zero Async Overhead - Pure synchronous API leveraging RocksDB's native performance
- ๐ ACID Transactions - Full transaction support with commit, rollback, and isolation
- ๐ Type-Safe Collections - Generic key-value storage with compile-time type checking
- ๐ฆ Column Families - Organize multiple typed collections in a single database
- โก Thread-Safe - Safe concurrent access using RocksDB's multi-threaded column families
- ๐พ Backup & Restore - Built-in point-in-time backup and disaster recovery
- ๐ Replication Infrastructure - Framework for distributed replication (network layer not included)
- ๐ Reference System -
Ref<T>type for efficient object relationships - ๐ฏ Zero RocksDB Exposure - Complete abstractionโusers never interact with RocksDB types
- ๐ Rich Operations - Batch writes, snapshots, multi-get, and functional iteration
Installation
Add to your Cargo.toml:
[]
= "1.0"
= { = "1.5", = ["derive"] }
Quick Start
use ;
Core Concepts
Collections
Collections provide type-safe access to column families:
// Save using the generated save() method
product.save?;
let products = collection?;
// Single operations
let item = products.get?;
products.delete?;
// Batch operations
let items = products.get_many?;
// Iteration
products.iter?.for_each?;
Transactions
ACID transactions ensure atomic operations:
let txn = db.transaction?;
let accounts = txn.?;
let mut alice = accounts.get?.unwrap;
let mut bob = accounts.get?.unwrap;
alice.balance -= 100;
bob.balance += 100;
accounts.put?;
accounts.put?;
txn.commit?;
Batch Operations
Efficient bulk writes:
let users = collection?;
let mut batch = users.batch;
for i in 0..1000
batch.commit?;
Snapshots
Point-in-time consistent reads:
let users = collection?;
let snapshot = users.snapshot?;
// Read from snapshot while database continues to change
let user = snapshot.get?;
Backup & Restore
// Create backup
db.backup?;
// List backups
let backups = list_backups?;
// Restore from backup
restore_from_backup?;
References
Efficiently store object relationships:
use ;
// The #[ngdb] macro automatically implements Referable
// Retrieve with automatic reference resolution
let posts = collection?;
let post = posts.get_with_refs?.unwrap;
println!;
Distributed Replication
NGDB provides the infrastructure for building distributed systems with eventual consistency. The library handles operation logging and conflict resolution, but you must implement the network layer (HTTP, gRPC, WebSocket, etc.) between nodes.
Architecture
Outbound Replication - Capture local writes as replication logs:
// Your code creates replication logs for writes
let log = create_replication_log;
// Send to peers via your network layer
send_to_peers.await?;
Inbound Replication - Process logs received from peers:
// In your network handler
async
NGDB handles:
- Operation serialization
- Timestamp-based conflict resolution
- Atomic batch replication
- Data integrity verification
You implement:
- Network transport (TCP, HTTP, gRPC, etc.)
- Peer discovery and routing
- Authentication and authorization
- Network failure handling
Examples
The repository includes comprehensive examples:
basic_usage.rs- CRUD operationsuser_struct.rs- Working with custom structsderive_macro.rs- Using the#[ngdb]macronested_refs.rs- Object relationships withRef<T>advanced.rs- Advanced features and patternstransactions.rs- ACID transactions with rollbackthread_safe_transactions.rs- Concurrent access patternsbackup_restore.rs- Disaster recoveryreplication.rs- Basic replication setupreplication_full.rs- Complete replication system
Run an example:
Performance
NGDB is designed for performance:
- Synchronous operations - No async runtime overhead
- Zero-copy where possible
- RocksDB optimizations - LZ4 compression, jemalloc (non-Windows)
- Efficient batching - Minimize write amplification
- Multi-threaded - Safe concurrent access to column families
License
Dual-licensed under MIT or Apache-2.0.
Acknowledgments
Built on RocksDB, a high-performance embedded key-value store originally developed at Facebook.
Serialization powered by Borsh, a binary serialization format optimized for speed and consistency.
Contributing
Contributions are welcome! Please ensure:
- Code passes
cargo test - Code is formatted with
cargo fmt - Code passes
cargo clippywith no warnings - New features include tests and documentation
- Follow existing code style