Slyber DB (SLDB) is a high-performance distributed transactional database written in pure Go with zero external cgo dependencies, uniting three storage engines inside a single core:
- Transactional KV Store with SSI (Serializable Snapshot Isolation): point and range operations, atomic 64-bit counters (
AddInt64), optimistic compare-and-swap locks (CAS), per-keyTTLexpiration, Read-Your-Own-Writes (RYOW), and distributed two-phase commit (2PC) across partitions and nodes. - Persistent Message Streams Engine (Streams): strict monotonic
Seqnumbering (1, 2, 3, ...), O(1) random reads via a dense 16-byte.sidxindex, persistentIdempKeydeduplication, server-side consumer group cursors, long-polling waits (WaitTimeout), in-place message editing (PatchStream), and physical sensitive-data erasure (RedactStream) via background Copy-on-Write repacking. - Reactive Subscription Bus (Watch): a 64-sharded event broker with a history ring buffer for seamless catch-up from a specific version (
afterVersion) and follower deduplication protection in cluster mode (FlagLeaderOnly).
Within real-time infrastructure, Slyber DB acts as a unified persistence layer for room state, chat history, event queues, and session quotas alongside Slyber SFU Server media clusters and Slyber TURN Server relays.
Key Architectural Properties
- Unified
db.DBcontract across all topologies: application code built with the Go SDK runs identically on an embedded in-process engine (ModeEmbedded), a single-node network server (ModeStandalone), and a fault-tolerant Multi-Raft cluster (ModeCluster). - Zero-GC hot path: performance-critical data structures (
ArenaSkipListin MemTable, a 64-shardedBlockCacheusing Clock Second-Chance eviction and Knuth backward-shift deletion, a fragmentedRangeDelIndex, and Raft log slots) live in flat, pointer-free byte arenas. - Key-Value separation: values ≤ 4 KiB are stored inline inside LSM
.ssttables, while values > 4 KiB (up to 15 MiB) are routed to segmentedValueLogfiles (vlog_*.dat) or directly into stream segments (slog_*.dat), eliminating write amplification during LSM compaction. - End-to-end integrity and encryption: every on-disk structure is protected by hardware-accelerated CRC32C (Castagnoli) checksums and optional AES-256-GCM encryption at rest with nonce-reuse protection via a monotonic
BootIncarnationcounter. Network traffic runs strictly over TLS 1.3 with mutual session-bound authentication using Exported Keying Material (EKM HMAC-SHA256) and pre-TLS CIDR filtering.
Namespaces
Every table, key collection, or message stream family is isolated by a 16-bit Namespace identifier (uint16):
0x0000(0,NamespaceSystemCatalog) and1..65534— available for user data and streams.0xFFFF(65535,NamespaceReservedEngine) — reserved exclusively for internal engine metadata (stream overlays and cursors, 2PC lock states,TxIDdeduplication, Raft state). Any user access to0xFFFFis immediately rejected withErrReservedNamespace.
Virtual Partitions, Colocation, and Shard Alignment
The keyspace is statically divided into 4096 virtual partitions (PartitionID from 0..4095). The routing function tuple.PartitionFor(ns, partKey, key) applies two rules:
- With a colocation key (
len(partKey) > 0):Namespaceis excluded from hashing (SplitMix64(FNV1a64(partKey)) & 0x0FFF). Records across different namespaces and Streams sharing the samepartKey(such asroom:774oruser:42) are guaranteed to land in the same virtual partition and can be mutated atomically in a single WAL write (ApplyBatchor a 1-RTTUpdatetransaction). - Without a colocation key (
partKey == nilor[]byte{}): the pair(Namespace, Key)is hashed, evenly distributing keys across all 4096 partitions and physical nodes.
Each node serves data through NumLocalShards independent physical shards (each owning its own Group Commit WAL pipeline, lsm.Engine, ValueLog, and stream.Manager). To eliminate cross-shard locking during replication in a Multi-Raft cluster and live partition migration, the engine enforces a strict alignment invariant:
NumLocalShardsmust be a power of two in1..64(shardMask = NumLocalShards - 1).NumReplicaGroupsmust be a multiple ofNumLocalShards(up to4096).- Any virtual partition
PartitionIDmay only be assigned to a replica groupGroupIDresiding on the same physical shard:(PartitionID & shardMask) == (GroupID & shardMask).
By default, partition pid belongs to replica group pid % NumReplicaGroups and physical shard pid & shardMask.
On-Disk Data Directory Layout
data/
├── LOCK # Exclusive OS flock (prevents double-starting a process)
├── IDENTITY # 64-byte node passport (NodeID, shard count, AES-256 key tag, CRC32C)
├── TOPOLOGY.bin # Persistent cluster map binding 4096 partitions to groups (CRC32C)
├── reserve.ballast # Preallocated ballast file for recovering from ENOSPC (ErrDiskFull)
└── shards/
├── 00/
│ ├── CURRENT # Pointer to the active MANIFEST file
│ ├── MANIFEST-000002 # LSM version log (L0..L4), live VLog segments, streams, and FlushedLSN
│ ├── wal_000001.log # Write-Ahead Log segments (Group Commit WAL)
│ ├── 000105.sst # Immutable LSM tables (data blocks, Index, Bloom, RangeDel, Bounds, Footer)
│ ├── vlog_000001.dat # Large value storage (> 4 KiB) managed by VLog GC
│ ├── slog_1_1.dat # Stream data segment (StreamInstanceID=1, BaseSeq=1, Gen=0)
│ ├── slog_1_1.sidx # Dense 16-byte O(1) offset and CRC32C index for slog_1_1.dat
│ └── slog_1_1_g1.dat # Generation Gen=1 after physical CoW erasure via RedactStream
├── 01/
└── ...
Important: The local shard count (
NumLocalShards) and encryption state (Encrypted) are permanently locked intodata/IDENTITYon first initialization. Opening an existing data directory with a mismatched shard count or encryption key fails withErrInvalidConfig.
Related Guides
- Server quick start: Linux Installation and Embedded / Standalone Modes
- Container deployment: Deploying with Docker and Docker Compose
- System limits and tuning: Limits, Configuration, and CLI Reference