Engine overview #
Startup sequence #
main() does a small, fixed amount of work, and the ordering matters:
godotenv.Load()— pick up.envif present.confInit(&conf)— parse flags, resolve--authfrom the environment, validate TLS pairing and--advertise, map--raft-backendtoleveldb/bolt.conf.DataDirReadyis registered as a callback: when the Raft layer has prepared the node directory it opens the storage backend (openStorage) and publishesldb. The command handlers only work after this point, which is why/readyzexists.- Backend metrics are registered with the
INFOcollector (hybriddb,ipfs,ipfs-synckv). --pprofand--metricsservers start, if enabled — both are plainnet/httpservers in goroutines.conf.Snapshot/Restoreare wired tosnapshot.go, connection hooks to the client counter, andrafthub.Main(conf)takes over: recover the log, join a cluster if-jwas given, serve RESP.
Request path #
Writes (the 56 commands registered with AddWriteCommand):
client → RESP parse → normalise (lowercase command name, args to strings)
→ leader check → append to Raft log → replicate → commit at quorum
→ apply on every node in log order → handler → ledis → driver
The handler executes during apply, not before the append, which is what makes the same result appear
on every node. A handler that reads the wall clock or math/rand would therefore diverge — it must use
m.Now()/m.Rand(), whose values are themselves replicated through the internal TICK command.
Reads (the 54 commands registered with AddReadCommand):
client → RESP parse → (openreads? local : leader) → handler → ledis → driver
A leader serves reads after ensuring its applied index covers the client’s own earlier writes. A
follower either answers -MOVED 0 <leader> or, with --openreads, serves what it has applied.
System commands (RAFT, CLUSTER, MACHINE, BARRIER) bypass the data space and talk to the Raft
wrapper directly.
Components and where they live #
| Layer | Implementation | Files |
|---|---|---|
| RESP server, pipelining, auth, Raft | tidwall/uhaha + tidwall/redcon | vendor/github.com/tidwall/uhaha |
| Data model, per-type keyspaces, TTLs | ledisdb/ledis | vendor/github.com/ledisdb/ledisdb/ledis |
| Command handlers | this repository | strings.go, hashes.go, lists.go, set.go, sorted_sets.go, scan.go, servers.go |
| Storage drivers | this repository + ledis | driver/*, vendor/.../store/goleveldb |
| Snapshots | this repository | snapshot.go |
| Observability | this repository + Prometheus client | observability.go, server_info.go |
Process model #
One process, one goroutine per connection, one Raft apply loop. There is no per-command thread pool and
no internal partitioning: a slow command blocks the apply loop, which is why LINSERT/LREM are
documented as O(n) hazards and BLPOP is not implemented at all.
Failure domains #
| Failure | Blast radius |
|---|---|
| A handler returns an error mid-write | The command fails; earlier applied writes stay applied (no rollback) |
| Backend write fails during a list rebuild | The list is left truncated (LINSERT/LREM) |
| Process crash | Uncommitted log entries are lost; committed entries are recovered from store/ |
| Node disk loss | The node rejoins from the leader’s log/snapshot; the cluster is unaffected while a majority lives |
| Majority loss | Writes stop (-CLUSTERDOWN); reads with --openreads continue |
What is deliberately not here #
No sharding, no SQL engine, no secondary indexes, no scripting, no pub/sub, no streams, no
transactions, no vector search. Element stores (IceFireDB-PubSub, the SQL proxies) are separate
binaries in this repository, not features of this one.