Skip to content

v2 vision: parallel writers, range indexes, streaming replication — quantum NEDB #2

Description

@Eth-Interchained

Context

During the Interchained Vision × NEDB integration (June 2026), we ran nedb-engine v1.0.4 as the primary read/write store for a live ITC block explorer — 620,000+ blocks, real production traffic, DualStore bi-directional writes with a backfill task filling historical blocks concurrently.

The integration works. But we hit the architectural ceiling of v1 repeatedly:

v1 Bottlenecks (confirmed in production)

1. Single-writer Sequencer

The Sequencer serialises all writes through one goroutine/thread. The Vision backfill (250 blocks/second target) competed directly with DualStore live writes (every block tick). Result: ReadTimeout errors on write responses while the Sequencer queue backed up. Workaround: split httpx clients (read=3s, write=30s). Root: fundamentally no parallelism in the write path.

2. AOF replay on startup is O(total writes)

After 520,000 block headers were written to nedbd, every restart hung for minutes while the AOF replayed. The /health endpoint responded but the query endpoint blocked until replay finished. For an encrypted 1.2M-row database, this was 10-30 minutes. Users experienced Vision as "hanging" after every redeploy.

3. NQL full scan — no sorted/range indexes

FROM blocks ORDER BY height ASC LIMIT 1 scans every document. With 620k blocks this is O(n). A B-tree index on height would make this O(log n). NQL supports eq indexes but not sorted indexes, so range queries (height > X, ORDER BY height) are always full scans.

4. HTTP/1.1 one-request-per-write

Even with the batch endpoint, the overhead of one HTTP connection per batch (TCP handshake, TLS, framing) limits throughput. 500 docs/request at 5ms round trip = 100 writes/second maximum. Redis RESP2 (already in nedbd) gives pipelining, but it's not wired to the write path.

v2 Architecture Goals — "Quantum NEDB"

Parallel write workers

  • Lock-free MVCC: N concurrent writers append to separate in-memory segments
  • Background compactor merges segments and flushes to AOF asynchronously
  • Writers never block each other; durability is configurable (sync/async/batch)
  • Target: 10,000+ writes/second on a single VPS

Sorted / range indexes

  • Automatic skip-list or B-tree index on numeric fields (height, timestamp, score)
  • ORDER BY height DESC LIMIT 10 → O(log n) not O(n)
  • Created lazily on first query that would benefit, persisted to disk
  • NQL planner uses index access paths when available

Instant cold start from snapshots

  • Checkpoint produces a compact snapshot (not full AOF replay)
  • Startup loads snapshot only; AOF tail (recent writes since last checkpoint) applied incrementally
  • Large databases (1M+ rows) should start in < 1 second
  • Auto-checkpoint after N writes or M seconds (configurable)

Streaming replication

  • nedbd instances replicate to each other via SSE or WebSocket
  • Push new AOF entries to replicas in real-time
  • Conflict resolution via vector clocks (last-writer-wins for KV, causal ordering preserved)
  • Enables: primary + hot standby, geo-distributed reads, zero-downtime deploys

Multiplexed write protocol

  • HTTP/2 or RESP3 for the write path — multiple in-flight ops on one connection
  • Binary framing for batch PUT (no JSON overhead for numeric values)
  • Backpressure: server signals when Sequencer queue is full, client pauses

v1.1 Milestones (near-term, before full v2)

These can land without a full rewrite:

  • Sorted indexes: POST /v1/databases/{name}/index {"coll":"blocks","field":"height","kind":"sorted"} — enables ORDER BY to use index
  • Auto-checkpoint on write threshold: reduce cold-start time without manual intervention
  • Startup non-blocking queries: health endpoint already non-blocking; queries should return empty (not block) while AOF is loading, instead of hanging the caller

Produced by

Interchained LLC × Claude Sonnet 4.6
Vision integration thread: https://hyperagent.com/thread/cmqfk14ul00q706adfz7zbvwh
Date: June 16, 2026

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions