A deterministic cloud native key-value database
  • Zig 99.8%
  • Python 0.2%
Find a file
Jeremy Tregunna ca3bbae353
Some checks are pending
CI / test (push) Waiting to run
refactor: rename kv table identifiers to namespaces
2026-06-27 20:34:27 -06:00
.github/workflows fix: cleanup 2026-04-23 16:15:18 -06:00
docs refactor: rename kv table identifiers to namespaces 2026-06-27 20:34:27 -06:00
src refactor: rename kv table identifiers to namespaces 2026-06-27 20:34:27 -06:00
.gitignore fix: cleanup 2026-04-23 16:15:18 -06:00
AGENTS.md docs: add AGENTS.md 2026-04-17 08:00:56 -06:00
build.zig feat: add transactional kv batches 2026-06-26 18:35:38 -06:00
config.json refactor: remove sql support 2026-06-26 15:39:08 -06:00
CONTRIBUTING.md feat: add EXECUTE statement and surface query hashes in the REPL 2026-04-27 20:17:44 -06:00
fix_build.py refactor: remove sql support 2026-06-26 15:39:08 -06:00
foldb-spec.md refactor: remove sql support 2026-06-26 15:39:08 -06:00
foldb.png chore: re-add foldb.png 2026-06-27 19:33:32 -06:00
LICENSE fix: cleanup 2026-04-23 16:15:18 -06:00
mise.toml chore: initial project setup 2026-04-17 07:41:57 -06:00
README.md refactor: remove sql support 2026-06-26 15:39:08 -06:00
zlint.json fix: resolve all zlint warnings across 83 files 2026-04-26 13:46:32 -06:00

foldb

foldb

A replicated, deterministic state machine key-value store written in Zig. The log is the source of truth; state is fold(log) — a pure function cached in an LSM tree. One global sequence number, no wall clocks inside the fold.

Status: single-node is stable. Multi-node replication (Raft transport) is in active development.

Requirements

Zig 0.16.0

Building

zig build                              # build
zig build test                         # unit + integration tests

Running

foldb serve --config config.json

Interactive REPL

foldb repl --host 127.0.0.1 --port 7432

Supports commands: set <key> <value>, get <key>, delete <key>, range <start> <end>, batch <file.json>, and exit.

foldb client --host 127.0.0.1 --port 7432 --command get --key "mykey"
foldb client --host 127.0.0.1 --port 7432 --command set --key "mykey" --value "myvalue"

Configuration

{
  "storage_dir": "/var/lib/foldb",   // required — where data is stored
  "node_id": 1,                      // unique integer per node in the cluster
  "listen_addr": "0.0.0.0",          // optional, default: 0.0.0.0
  "listen_port": 7432,               // optional, default: 7432
  "peers": [],                       // optional — list of peer objects
  "max_epoch_size": 10000,           // optional — max transactions per Raft epoch
  "election_timeout_min_ms": 150,    // optional — Raft election timeout range
  "election_timeout_max_ms": 300,
  "heartbeat_interval_ms": 50        // optional — Raft heartbeat interval
}

Architecture

  • Wire Protocol — Custom binary protocol (frames, streams, typed messages) over TCP.
  • Gateway — Validates requests, submits mutations through the Sequencer, serves reads from Storage.
  • Sequencer — Global ordering via Raft consensus. Assigns monotonically increasing sequence numbers.
  • Executor — Folds committed log entries into Storage deterministically.
  • Storage — LSM tree (L0-L2 local, L3 optional object store). Opaque byte values.
  • CDC — Change Data Capture streams before/after images of mutations.

Docs

  • docs/internal/ — subsystem reference (storage, log, gateway, sequencer, CDC, network)

License

Copyright © Jeremy Tregunna. Released under the Apache 2.0 License.