RustLite
RustLite is a lightweight, high-performance embedded database written entirely in Rust. Designed for applications that need a fast, reliable, and embeddable storage solution with ACID guarantees.
โ ๏ธ Important: RustLite is a key-value store with MVCC transactions, not a full relational database. It's similar to LevelDB or RocksDB (but with transactions), NOT SQLite or PostgreSQL. While it includes a basic SQL-like query engine for simple SELECT operations, it lacks schemas, CREATE TABLE, data types, functions, and constraints. For full SQL support, use rusqlite or SQLite directly.
๐ฏ Vision
RustLite aims to be the go-to embedded database for Rust applications, combining:
- Performance: Zero-copy operations, memory-mapped I/O, and efficient data structures
- Reliability: Full ACID compliance with write-ahead logging and crash recovery
- Simplicity: Single-file deployment, zero configuration, intuitive API
- Safety: Memory-safe by design using Rust's type system and ownership model
๐ก Ideal Use Cases
RustLite excels in scenarios where you need fast, transactional key-value storage:
- ๐ฑ Embedded Applications: Mobile/desktop apps needing local data storage
- ๐ง Application State: Configuration, settings, and application metadata
- ๐พ Caching Layer: High-performance caching with persistence
- ๐ซ Session Storage: Web session management with ACID guarantees
- ๐ Time-Series Data: Event logs, metrics, and analytics data
- ๐ Event Sourcing: Append-only event stores with snapshot isolation
- ๐จ Message Queues: Lightweight job queues and task schedulers
- ๐ฎ Game State: Player progress, inventory, and game world persistence
- ๐ Document Storage: Key-based document retrieval (JSON, MessagePack, etc.)
- ๐ Credential Vaults: Secure local storage for API keys and secrets
Not Ideal For:
- โ Complex relational queries with JOINs across multiple tables
- โ Applications requiring SQL compatibility (use SQLite/PostgreSQL)
- โ Full-text search (no FTS support yet)
- โ Large-scale distributed systems (single-node only)
โจ Features
Current (v0.7.0)
- โ Persistent storage with LSM-tree architecture
- โ Write-Ahead Logging (WAL) for crash recovery
- โ SSTable compaction for optimized disk usage
- โ Snapshot backups for point-in-time recovery
- โ B-Tree indexing for range queries and ordered lookups
- โ Hash indexing for O(1) exact-match lookups
- โ SQL-like query engine with SELECT, WHERE, LIMIT support
- โ Aggregate functions: COUNT(*), COUNT(column), SUM, AVG, MIN, MAX
- โ GROUP BY with multiple columns and HAVING clauses
- โ Full MVCC transactions with snapshot isolation
- โ JOIN operations (INNER, LEFT, RIGHT, FULL OUTER)
- โ Hash join and nested loop join algorithms
- โ Production logging with structured tracing
- โ Thread-safe concurrent access
- โ Simple, ergonomic API
Roadmap
- ๐ v0.8: Additional SQL features and optimizations
- ๐ v1.0: Production-ready with full ACID guarantees
See docs/ROADMAP.md for detailed plans.
๐ Quick Start
Add RustLite to your Cargo.toml:
[]
= "0.5"
Transactions with MVCC (v0.5.0+)
use ;
Isolation Levels:
ReadUncommitted: Fastest, may see uncommitted changesReadCommitted: See only committed dataRepeatableRead: Snapshot isolation (default)Serializable: Strictest consistency
See examples/transaction_demo.rs for comprehensive examples.
Persistent Database (Recommended)
use Database;
Data Persists Across Restarts
use Database;
// First run - write data
let db = open?;
db.put?;
drop;
// Later - data is still there!
let db = open?;
assert_eq!;
In-Memory Database (For Testing)
use Database;
// Fast in-memory storage (data lost when program exits)
let db = in_memory?;
db.put?;
Indexing for Fast Lookups (v0.3.0+)
use ;
let db = in_memory?;
// Create indexes
db.create_index?; // O(1) lookups
db.create_index?; // Range queries
// Index your data
db.put?;
db.index_insert?;
db.index_insert?;
// Fast lookups
let user_ids = db.index_find?;
println!; // Output: 1
Relational Data with Foreign Keys
See examples/relational_demo.rs for a complete example showing:
- Users and Orders tables
- Foreign key relationships
- Primary and secondary indexes
- Join queries and cascade deletes
๐ฆ Installation
From crates.io
From source
๐๏ธ Architecture
RustLite is built with a modular LSM-tree architecture:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Database API โ
โ (rustlite crate) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โ Indexing โ โ Memtable โ โ WAL โ โ
โ โ B-Tree + โ โ (BTreeMap) โ โ (Write Log) โ โ
โ โ Hash โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ SSTable Storage + Compaction โ โ
โ โ (Sorted String Tables on Disk) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโ โ
โ โ Snapshot โ Point-in-time backups โ
โ โ Manager โ โ
โ โโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Key Components:
- Indexing: B-Tree for range queries, Hash for O(1) lookups
- Memtable: In-memory sorted buffer for fast writes
- WAL: Write-ahead log for crash recovery and durability
- SSTable: Immutable on-disk sorted files
- Compaction: Background merging to reduce read amplification
- Snapshot: Point-in-time backups for disaster recovery
See docs/ARCHITECTURE.md for technical details and docs/README.md for the full documentation index.
๐ Production Logging (v0.6+)
RustLite includes production-grade structured logging:
use LogConfig;
use Database;
See docs/LOGGING.md for comprehensive logging guide.
๐ค Contributing
We welcome contributions! Please see our CONTRIBUTING.md for guidelines.
Key areas where we need help:
- Query optimizer and query planner
- Performance benchmarking and optimization
- Documentation and examples
- Platform-specific optimizations
- Advanced indexing (full-text search, spatial indexes)
๐ Requirements
- Rust 1.81.0 or later
- Supported platforms: Linux, macOS, Windows
๐งช Testing
# Run all tests (48 tests: 39 lib + 9 aggregate)
# Run with logging
RUST_LOG=debug
# Run examples
# Run benchmarks
๐ Benchmarks
Performance benchmarks will be published as the project matures. Early benchmarks show:
- Sequential writes: TBD
- Random reads: TBD
- Concurrent operations: TBD
๐ Security
RustLite takes security seriously. Please report any security vulnerabilities to security@rustlite.dev.
๐ License
This project is licensed under the Apache License, Version 2.0 (LICENSE or http://www.apache.org/licenses/LICENSE-2.0).
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in RustLite by you shall be under the terms and conditions of the Apache License, Version 2.0, without any additional terms or conditions.
๐ Acknowledgments
RustLite is inspired by excellent databases like SQLite, LevelDB, and RocksDB.
๐ Contact & Community
- GitHub: github.com/VIRTUMEM-AI-LABS/rustlite
- Crates.io: crates.io/crates/rustlite
- Documentation: docs.rs/rustlite
- Discord: Coming soon
- Website: rustlite.dev (planned)
๐บ๏ธ Status
Current Status: Active development (v0.3.0)
RustLite is in active development with persistent storage, WAL, and indexing capabilities. Not yet production-ready, but suitable for experimentation and development. Star the repo to follow our progress toward v1.0!
Made with โค๏ธ by the RustLite community