Skip to content
October 14, 2026•9 min read•By Dzaki Amri Zaidaan

SurrealMX 1.0: Inside SurrealDB's New In-Memory Storage Engine for AI Workloads

SurrealMX 1.0 replaces SurrealDB's LSM-tree backend with a lock-free, epoch-based in-memory engine targeting sub-millisecond vector and graph queries. We break down the architecture, the MVCC mechanics, and the real cost/latency trade-offs for production AI systems.

#AI & ML#Database
cable network

The Problem & Industry Shift

SurrealDB's original storage layer was built on a log-structured merge (LSM) tree with an append-only write-ahead log, similar in spirit to RocksDB [1]. That design is excellent for durability and write amplification control, but it imposes a structural tax on the workloads SurrealDB is now being asked to serve: multi-model AI applications that combine vector similarity search, graph traversal, and document queries in a single transaction.

The problem is that an LSM tree forces every read to potentially touch multiple levels of sorted runs, and every write to be buffered in a memtable before being flushed. For a vector index doing 10k nearest-neighbor probes per query, or a graph traversal hopping 5 edges deep, that read amplification compounds fast. The industry shift is clear: as embeddings and knowledge graphs move from batch pipelines into interactive, agent-driven applications, the storage engine becomes the latency floor. Disk-resident LSM engines typically land in the 1-10ms p50 range for point reads; agent loops that issue dozens of such reads per turn cannot tolerate that.

SurrealMX 1.0 is SurrealDB's answer: a purpose-built in-memory storage engine that keeps the entire working set in RAM, uses epoch-based reclamation instead of garbage collection, and exposes the same SurrealQL surface. The bet is that for AI workloads, memory is cheaper than latency.

Architecture & Core Mechanics

SurrealMX is not "SurrealDB with a RAM disk." It is a distinct storage engine selected per-namespace via the ENGINE clause. The core design has four moving parts:

                 SurrealQL Query
                       |
                       v
            +---------------------+
            |   Query Planner     |
            +----------+----------+
                       |
        +--------------+--------------+
        |              |              |
        v              v              v
  +-----------+  +-----------+  +-----------+
  | Document  |  |  Vector   |  |  Graph    |
  |  Index    |  |  (HNSW)   |  |  Index    |
  +-----+-----+  +-----+-----+  +-----+-----+
        |              |              |
        +------+-------+------+-------+
               |              |
               v              v
        +-------------+  +-------------+
        |  MVCC Layer |  | Epoch GC    |
        | (versioned  |  | (reclaim    |
        |  pointers)  |  |  retired    |
        +------+------+  |  versions)  |
               |         +------+------+
               v                |
        +-----------------------------+
        |   In-Memory Arena (RAM)     |
        |   + WAL (durability only)   |
        +-----------------------------+

1. Arena-allocated nodes. Every record, edge, and vector is stored in a slab-style arena with 64-byte alignment. Pointers are 32-bit offsets into the arena rather than 64-bit virtual addresses, which roughly halves the memory footprint of the index structures and improves cache locality on the hot path.

2. MVCC via versioned pointers. SurrealMX implements multi-version concurrency control with a per-record version chain. Readers acquire a snapshot by capturing the current global epoch counter; writers append new versions and atomically swap the head pointer. There are no read locks, so read throughput scales linearly with cores.

3. Epoch-based reclamation. Instead of a tracing GC, SurrealMX uses epoch-based reclamation (EBR), the same family of algorithms used in crossbeam and Linux RCU [2]. A version is only freed once every active reader has advanced past the epoch in which it was retired. This gives deterministic, bounded pause times — critical for agent loops that cannot afford a 50ms GC spike mid-tool-call.

4. WAL for durability, not reads. The write-ahead log still exists, but it is no longer on the read path. It is fsync'd on commit boundaries and replayed on restart to rebuild the arena. This means durability semantics are unchanged from the LSM engine, but reads never touch disk.

Production Code Example

The following TypeScript example uses the official SurrealDB SDK [3] to define a namespace backed by SurrealMX, create a vector index, and run a hybrid graph + vector query. Inline comments highlight the engineering decisions that matter.

import { Surreal } from 'surrealdb';

const db = new Surreal();

async function bootstrap() {
  // Connect over WebSocket; SurrealMX is a server-side engine choice,
  // not a client-side one, so the transport is unchanged.
  await db.connect('wss://db.internal:8000/rpc');
  await db.signin({ username: 'root', password: process.env.SURREAL_PASS! });

  // Select SurrealMX for this namespace. The engine is fixed at
  // namespace creation time; you cannot migrate an existing LSM
  // namespace in place without an export/import cycle.
  await db.use({ namespace: 'agents', database: 'memory' });

  // Define a document table with an HNSW vector index.
  // DIMENSION must match your embedding model exactly (e.g. 1536 for
  // text-embedding-3-small). M and EFC are HNSW build parameters:
  // higher M = better recall, more RAM. 16/200 is a sane default.
  await db.query(`
    DEFINE TABLE memory SCHEMAFULL;
    DEFINE FIELD content   ON memory TYPE string;
    DEFINE FIELD embedding ON memory TYPE array<float>;
    DEFINE FIELD agent_id  ON memory TYPE record<agent>;

    DEFINE INDEX memory_vec ON memory
      FIELDS embedding
      HNSW DIMENSION 1536 DIST EUCLIDEAN
      TYPE F32 M 16 EFC 200;

    -- Graph edges live in the same engine, so a traversal and a
    -- vector probe can share one MVCC snapshot.
    DEFINE TABLE recalls TYPE RELATION IN memory OUT memory;
  `);
}

async function recall(agentId: string, queryVec: number[], k = 8) {
  // Single round-trip: vector ANN + graph expansion in one snapshot.
  // Because SurrealMX holds everything in RAM, the planner can afford
  // to fuse these without a disk seek between stages.
  const [rows] = await db.query<[Array<{ content: string; score: number }>]>(
    `
    LET $seeds = SELECT id, content,
                        vector::distance::euclidean(embedding, $q) AS score
                 FROM memory
                 WHERE agent_id = $agent
                 ORDER BY score ASC
                 LIMIT $k;

    -- Expand one hop along the recalls graph to pull in related
    -- memories the ANN search missed. This is the hybrid pattern
    -- that LSM-backed engines struggle to serve at low latency.
    SELECT content, score FROM (
      SELECT * FROM $seeds
      UNION
      SELECT content, score FROM recalls
        WHERE in IN $seeds.id
    ) ORDER BY score ASC LIMIT $k * 2;
    `,
    { q: queryVec, agent: agentId, k }
  );
  return rows;
}

The critical detail is the LET $seeds binding: SurrealMX evaluates it once and reuses the materialized result set across the union, avoiding a second ANN probe. On an LSM engine this pattern often triggers a re-read from disk.

Performance, Cost & Trade-offs

SurrealDB's published benchmarks for SurrealMX 1.0 report p50 point reads under 100µs and vector ANN queries in the 1-3ms range for 1M 1536-dim vectors on a 32-core, 256GB instance [4]. Those numbers are plausible given the architecture, but they come with hard constraints:

DimensionLSM EngineSurrealMX 1.0
p50 point read1-5 ms< 0.1 ms
p99 under load20-50 ms (compaction)1-5 ms (EBR bounded)
Working set limitDisk-boundRAM-bound
Cost modelCheap disk, expensive IOPSExpensive RAM, cheap IOPS
DurabilityWAL + SSTablesWAL only
Cold startFast (mmap)Slow (full WAL replay)

Memory is the budget. A 1M-vector HNSW index at 1536 dims with F32 storage consumes roughly 6GB for the raw vectors plus 1-2GB for the graph structure. Add documents, edges, and MVCC version chains, and a "small" AI workload can easily need 32-64GB of RAM. At current cloud pricing that is $1-2/GB/month, so a 64GB instance runs $64-128/month before compute — versus a few dollars for equivalent disk. The trade-off only pays off if your latency SLA justifies it.

Cold start is a real risk. Because the arena is rebuilt from the WAL on restart, recovery time scales with WAL size. For a 64GB working set you should expect tens of seconds to minutes of unavailability after a crash. Mitigation: run SurrealMX behind a read-through cache (Redis or a local LRU) so the application degrades gracefully during replay.

MVCC version chains grow under write-heavy loads. EBR bounds pause times but not memory. A hot record updated 10k times per second will accumulate versions until readers advance. Monitor surreal_engine_mvcc_versions and alert if it trends upward without bound.

Security note: in-memory engines are more sensitive to memory disclosure vulnerabilities, since a single out-of-bounds read can expose adjacent records. SurrealMX uses arena offsets rather than raw pointers specifically to reduce this surface, but you should still enable memory encryption at rest (AMD SEV / Intel TDX) for multi-tenant deployments.

Actionable Checklist / Summary

Before adopting SurrealMX 1.0 in production:

  • Size your RAM for 2x working set. Include vectors, graph edges, MVCC version chains, and HNSW overhead. Do not size for raw data alone.
  • Benchmark your actual query mix. SurrealMX wins on read-heavy, latency-sensitive workloads. If you are write-dominated with relaxed SLAs, the LSM engine is still the right choice.
  • Plan for cold start. Measure WAL replay time on a production-sized dataset. Add a read-through cache in front of SurrealMX.
  • Pin HNSW parameters deliberately. M and EFC trade RAM for recall. Start at M=16, EFC=200 and tune against your recall@k target.
  • Monitor MVCC version depth. Alert on unbounded growth; it signals a long-running reader pinning an old epoch.
  • Keep the WAL on fast, durable storage. NVMe with power-loss protection. The WAL is now your only durability guarantee.
  • Test failover explicitly. Kill the process under load and measure recovery time and data loss window.

SurrealMX is a bet that for AI-native applications, the storage engine's job has shifted from "store everything cheaply" to "serve everything instantly." That bet is correct for agent memory, real-time RAG, and interactive graph exploration — and wrong for archival or analytics workloads. Choose accordingly.

References