Embedded B+ tree storage engine in pure Zig. No C, no dependencies.
MVCC, copy-on-write pages, crash-safe commits via ping-pong meta, and a GC tree that keeps the file size bounded. Compiles to a single object file.
Public API — Environment · Transaction · Cursor · DBI
B+ Tree — splits · rebalance · overflow pages · dupsort
MVCC / GC — snapshot isolation · reader slots · FreeDB
OS Layer — mmap · file locking · Windows + POSIX
File layout:
Page 0-1 meta slots (ping-pong, atomic commit)
Page 2 main B+ tree root
Page 3 GC tree root
Page 4+ data pages
- Copy-on-write: writers never touch pages visible to active readers
- Readers never block writers, writers never block readers
- Named sub-databases (DBIs) within a single file
- DupSort, integer keys, reverse keys, custom comparators
- Nested transactions
- Overflow pages for large values
- Spill list for large write transactions
- GC coalescing keeps the free-page tree O(1)
- Hot backup via
env.copy() - Full page checksums (FNV-1a), verified on read
env.check()for integrity audits- Windows and POSIX
constmonolith=@import("monolith");
varenv=trymonolith.Environment.open("data.monolith", .{}, 16, 1<<30);
deferenv.close();
// Writevartxn=trymonolith.Transaction.begin(&env, null, .{});
errdefertxn.abort();
constdbi=trytxn.openDbi("users", .{ .create=true });
trytxn.put(dbi, "alice", "admin", .{});
trytxn.commit();
// Readvarrtxn=trymonolith.Transaction.begin(&env, null, .{ .rdonly=true });
deferrtxn.abort();
constrdbi=tryrtxn.openDbi("users", .{});
constval=tryrtxn.get(rdbi, "alice"); // ?[]const u8zig build
zig test src/lib.zigRequires Zig 0.16.
MIT