NEDB Docs / Running it / Replication

NEDB is single-node by design — but it ships the contract that replicas and followers need: a tip to poll, a bounded changefeed to drain, a readiness gate to trust, and state roots to prove two stores agree.

The replication contract

PrimitiveWhat it gives you
tip() / tip_collection()the latest write — the "am I behind?" check
since(cursor)a bounded changefeed of everything after a cursor; has_more is true whenever the cursor is behind head
scan_status() / seq_index_readyreadiness — gate replication on this, not on scan_complete
Why the gate matters: on a warm boot the seq index is empty by design (it rebuilds from the cold scan). A since() drain that trusted "zero nodes, has_more = false" would conclude it was caught up while holding none of the records. has_more is now true whenever the cursor is behind head, and seq_index_ready says when the index can actually serve.

State roots — comparing two stores in one hash

A state root commits to what a database currently says — which collections exist and what is in them — computable from live state alone, equal for any two databases holding the same data regardless of route. Uses: replica agreement, drift detection, anchoring, and the before/after of a diff.

The format (state_root_v1) is specified in docs/state-root-v1.md and pinned by test vectors (vectors/state_root_v1.json) that both engines must produce byte-identically — a format pinned by one implementation is not pinned. Leaves commit to logical content, not object hashes: with encryption on, a node's hash is a function of its ciphertext (fresh nonce per write), so hashing objects would make equal data produce different roots.

Live events

GET /events streams SSE: cold-scan progress (objects, rate, ETA), the ready event, and a write event per commit carrying the seq, collection and new Merkle head — a follower can tail the chain itself. Query subscriptions (POST /subscribe) push when a query's results change.

Honest scope

This is a replication contract, not a consensus layer. There is no built-in Raft, no automatic failover, no distributed transactions. If you need multi-master consensus, put a coordinator above NEDB and use the contract to keep its followers honest. What the contract does give you: proofs. A follower can verify its store against the source's head, roots and per-object hashes without trusting it.