Overview

Engine overview #

Startup sequence #

main() does a small, fixed amount of work, and the ordering matters:

  1. godotenv.Load() — pick up .env if present.
  2. confInit(&conf) — parse flags, resolve --auth from the environment, validate TLS pairing and --advertise, map --raft-backend to leveldb/bolt.
  3. conf.DataDirReady is registered as a callback: when the Raft layer has prepared the node directory it opens the storage backend (openStorage) and publishes ldb. The command handlers only work after this point, which is why /readyz exists.
  4. Backend metrics are registered with the INFO collector (hybriddb, ipfs, ipfs-synckv).
  5. --pprof and --metrics servers start, if enabled — both are plain net/http servers in goroutines.
  6. conf.Snapshot/Restore are wired to snapshot.go, connection hooks to the client counter, and rafthub.Main(conf) takes over: recover the log, join a cluster if -j was 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 #

LayerImplementationFiles
RESP server, pipelining, auth, Rafttidwall/uhaha + tidwall/redconvendor/github.com/tidwall/uhaha
Data model, per-type keyspaces, TTLsledisdb/ledisvendor/github.com/ledisdb/ledisdb/ledis
Command handlersthis repositorystrings.go, hashes.go, lists.go, set.go, sorted_sets.go, scan.go, servers.go
Storage driversthis repository + ledisdriver/*, vendor/.../store/goleveldb
Snapshotsthis repositorysnapshot.go
Observabilitythis repository + Prometheus clientobservability.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 #

FailureBlast radius
A handler returns an error mid-writeThe command fails; earlier applied writes stay applied (no rollback)
Backend write fails during a list rebuildThe list is left truncated (LINSERT/LREM)
Process crashUncommitted log entries are lost; committed entries are recovered from store/
Node disk lossThe node rejoins from the leader’s log/snapshot; the cluster is unaffected while a majority lives
Majority lossWrites 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.