System Architecture
A deep dive into the internals of SoliDB — a high-performance, distributed, multi-model database built with Rust.
Overview
SoliDB is engineered for performance, scalability, and developer experience. It combines document storage, graph traversal, full-text search, and time-series capabilities in a single, cohesive system.
Lines of Rust
Core Modules
Index Types
SDBQL Functions
Axum + Tokio
Sharding + Sync
SDBQL Engine
RocksDB
Core Features
Document Store
Schema-free JSON documents with optional JSON Schema validation. Auto-generated keys (UUIDv7) and atomic updates.
Graph Database
Native graph traversal with SDBQL. Edge collections, vertex relationships, and path queries.
Full-Text Search
Built-in fulltext indexing with n-gram tokenization and fuzzy matching support.
Geo Spatial
Geo indexes with haversine distance, radius queries, and nearest-neighbor search.
TTL Indexes
Time-to-live indexes for automatic document expiration. Perfect for caching and sessions.
Live Queries
Real-time WebSocket subscriptions with SDBQL. Push updates on document changes.
Transactions
ACID transactions with WAL (Write-Ahead Log). Commit, rollback, and isolation levels.
Job Queues
Built-in priority queues with scheduling, retries, and dead-letter handling.
Time Series
Optimized storage for time-series data with ranged pruning and downsampling aggregations.
Lua Scripting
Server-side Lua scripts for custom logic, triggers, and stored procedures.
Columnar Storage
Column-oriented storage engine with LZ4 compression. Optimized for analytics, aggregations, and report generation.
Rust Internals
SoliDB is written in Rust for memory safety, zero-cost abstractions, and fearless concurrency. This section explains how the Rust codebase is organized and how data flows through the system.
Query Execution Flow
Core Modules
sdbql/
Query language implementation with lexer, parser, AST, and executor (297KB core executor).
storage/
RocksDB-backed persistence with collections, indexes, and TTL management (125KB collection module).
server/
Axum HTTP API and WebSocket handlers (241KB handlers module). Handles routing, auth, and real-time.
cluster/
Node coordination with Hybrid Logical Clocks (HLC) for distributed timestamp ordering.
sync/
Master-master replication worker. Handles change propagation, blob sync, and conflict resolution.
sharding/
Horizontal partitioning with automatic rebalancing. Shard coordinator is 151KB.
transaction/
ACID transactions with configurable isolation levels and Write-Ahead Log (WAL) support.
scripting/
Embedded Lua 5.4 runtime for custom endpoints, triggers, and stored procedures with sandbox.
driver/
MessagePack binary protocol for high-performance clients. Internal cluster communication.
Architectural Patterns
Multiplexed Port
SoliDB uses a single port for all protocols via protocol detection:
- HTTP — REST API, SDBQL queries
- WebSocket — Live queries, chat
- Driver — MessagePack binary
- Cluster — Inter-node sync
Async Runtime
Tokio async runtime with work-stealing scheduler:
async/.await— Non-blocking I/Ospawn_blocking— CPU-intensive opsArc<RwLock<T>>— Shared statetokio::sync— Channels, semaphores
Serialization
Serde-based serialization throughout:
JSON— REST API, storageMessagePack— Driver protocolBincode— Internal storagePostcard— Embedded scenarios
Error Handling
Unified error handling pattern:
Entry Points
├── init_tokio() → Runtime
└── start_server(config) → Services
pub use storage::*;
Code Quality Standards
All code passes cargo fmt --check and cargo clippy -- -D warnings before commits. The codebase has 592 tests across 54 test files ensuring reliability.
Technology Stack
Core Runtime
- Rust: Memory safety, zero-cost abstractions, no garbage collection.
- Tokio: Async runtime with work-stealing scheduler (multi-threaded).
- Tower: Middleware stack for request/response pipelines.
Storage Engine
- RocksDB: LSM-tree storage with column families, compression, compaction.
- Column Families: Separate namespaces for collections, indexes, metadata.
- Write Batches: Atomic multi-key operations for consistency.
Network Layer
- Axum: Type-safe, ergonomic HTTP framework built on Hyper.
- WebSocket: Tokio-tungstenite for live queries and changefeeds.
- Reqwest: HTTP client for inter-node cluster communication.
Tooling & Serialization
- Serde: Zero-copy JSON serialization/deserialization.
- mlua: Lua 5.4 interpreter for server-side scripting.
- Tracing: Structured logging with span-based instrumentation.
- jsonwebtoken: JWT-based authentication and authorization.
Project Structure
Storage Layer
The storage layer provides an abstraction over RocksDB using column families for isolation. Each collection gets its own column family with documents, indexes, and metadata stored using prefixed keys.
Key Components
StorageEngine— Database instance managerCollection— Document operations, indexingDocument— JSON wrapper with key/valueIndex— Compound index metadataGeoIndex— Spatial index with RTrees
Key Prefixes
Index Types
Sorted B-tree
O(1) lookup
N-gram tokens
Haversine
Expiration
JSON Schema Validation
While SoliDB is schema-less by default, it supports optional JSON Schema validation at the collection level. This allows you to enforce data integrity rules while maintaining flexibility.
Validation Modes
- off No validation (default). Any valid JSON is accepted.
- strict Rejects any document that violates the schema. Returns formatted error details.
- lenient Accepts invalid documents but logs warnings. Useful for schema migrations or testing.
Configuration
Schemas are stored in the _schema system collection and can be updated at any time.
Standard Compliance
SoliDB uses the jsonschema crate, supporting Draft 7, Draft 2019-09, and Draft 2020-12 specifications. Complex validation rules like oneOf, pattern, and dependencies are fully supported.
SDBQL Engine
SDBQL (SoliDB Query Language) is an AQL-inspired query language with 100+ built-in functions. It supports document queries, graph traversal, aggregations, and data manipulation.
Query Capabilities
Multi-source iteration over collections, ranges, and static arrays.
Advanced filtering with optimized index usage and logical operators.
Variable declarations, intermediate results, and subqueries.
Data reduction via COLLECT with COUNT and AGGREGATE.
Native graph traversal with edge/vertex hops and path finding.
Pattern matching using LIKE and regular expressions (=~, !~).
Atomic multi-document mutations within the query flow.
Flexible response construction with projection and mapping.
Built-in Functions Reference
String & Pattern
Numeric & Math
Array Operations
Aggregation (Arrays)
Object & JSON
Date & Time
Geo & Search
Type Checking
Utilities
Server & API
The HTTP server is built on Axum with async handlers powered by Tokio. It provides RESTful endpoints, WebSocket support, and JWT-based authentication.
HTTP Endpoints
/_api/query— SDBQL execution/_api/document— CRUD operations/_api/collection— Management/_api/index— Index operations/_api/blob— Binary storage
WebSocket
/ws/live— Live queries/ws/changefeed— Real-time changes/ws/presence— User presence- Multiplexed connections
Authentication
- JWT Bearer tokens
- Database-level auth
- Admin vs user roles
- Token refresh flow
Cluster & Sharding
SoliDB supports horizontal scaling through sharding. Collections can be distributed across multiple nodes with configurable replication factors.
Cluster Module
ClusterManager— Node registration, heartbeatsHealthChecker— Node liveness detectionHLC— Hybrid Logical Clocks for orderingClusterState— Membership and topology
Sharding Module
ShardCoordinator— Shard assignment, healingDistribution— Replica placement algorithmsMigration— Live shard rebalancingRouter— Request routing to primaries
Replication Flow
Transactions
SoliDB provides ACID transactions with a Write-Ahead Log (WAL) for durability. Transactions support multiple operations across collections.
Transaction API
BEGIN— Start transactionCOMMIT— Apply changesROLLBACK— Discard changes- Collection locking
WAL (Write-Ahead Log)
- Append-only log file
- Crash recovery
- Log truncation
- Replay on startup
Isolation Levels
- Read Uncommitted
- Read Committed
- Snapshot Isolation
Lua Scripting
Server-side Lua 5.4 scripts enable custom business logic, API endpoints, and background jobs. Scripts run in a secure sandbox with access to SDBQL and HTTP utilities.
Script Types
- GET/POST/PUT/DELETE: Custom API endpoints
- WS: WebSocket handlers
- Scheduled: Cron-like execution
- Triggers: Document change handlers
Available APIs
sdbql(query)— Execute SDBQLfetch(url, opts)— HTTP clientjson.encode/decode— JSON handlingcrypto.*— Hash, HMAC, JWTtime.*— Date/time utilitieslog.*— Debug logging (debug, info, error)