Graph and Cypher · Engineering

Graph traversal on ordinary documents

How NonoDB treats nodes and edges as documents, maintains adjacency transactionally, and bounds traversal cost.

Graph features usually arrive as a separate database. That makes sense when the product is a graph: you want a graph query language, graph algorithms, and a storage engine built around relationships.

Many applications are not graph products. They have users, orders, devices, and a few relationships between them. Adding a graph database for a recommendation feature can cost more operationally than the feature is worth.

NonoDB treats ordinary documents as a property graph. A node is a document in a node collection; an edge is a document in an edge collection. There is no separate graph storage format.

Defining a graph

{"op":"set_graph",
"coll":"nodes",
"def":{
"node_collection":"nodes",
"edge_collection":"edges",
"from_field":"from",
"to_field":"to",
"label_field":"label",
"weight_field":"weight",
"directed":true
}}

Edges look like this:

{"_id":"e1","from":"alice","to":"bob","label":"KNOWS","weight":0.8}

set_graph validates every existing edge, writes the definition, and rebuilds the adjacency index in one write transaction. A malformed edge aborts the whole change. Vault collections cannot be node or edge collections.

Traversal

{"op":"traverse",
"coll":"nodes",
"start":["alice"],
"direction":"out",
"labels":["KNOWS"],
"max_depth":2,
"algorithm":"bfs",
"tree":true,
"edge_filter":{"weight":{"$gte":0.5}},
"node_filter":{"status":"active"},
"limit_nodes":1000,
"limit_edges":10000,
"max_bytes":67108864}

The traversal reads one LMDB snapshot. BFS or DFS follows the adjacency index, with optional edge labels, direction, edge filters, node filters, and a temporal as_of instant.

Compact adjacency values carry only edge id, label, weight, and validity. Full edge documents are fetched only for include_edges or edge_filter. A node is expanded once; a later arrival is returned as a cycle marker instead of being expanded again.

Results include nodes, edges, truncated, and missing. Budgets bound node records, inspected edges, and serialized bytes. A truncated traversal is partial by design; it does not pretend to have explored the whole graph.

Why adjacency is transactional

The adjacency index is derived data, but it is not eventually consistent. Entries are written and removed in the same LMDB transaction as the edge document. That covers insert, update, delete, pipeline updates, TTL expiry, replication apply, and write_batch.

A crash cannot leave adjacency ahead of or behind the edge document. reindex_graph can rebuild it after an upgrade or corruption; an online rebuild writes a new generation while readers keep using the active one, mirrors concurrent edge writes into both, then swaps atomically.

That is a stronger consistency story than a separate graph database fed by a change stream.

Filters and temporal edges

edge_filter and node_filter use the normal document filter language. They are evaluated against the full documents, not only the compact adjacency summary.

as_of follows only edges valid at a given instant when valid_from_field and valid_to_field are configured. That is useful for “who managed this account on date X” questions without a separate temporal graph store.

Projection is flat and always retains _id. Vault collections are rejected.

Limits

Limit Value
start ids 10,000
max_depth 64
default limit_nodes 1,000
max limit_nodes 100,000
default limit_edges 10,000
max limit_edges 100,000
default max_bytes 64 MiB
max max_bytes 256 MiB
labels 64 entries, each ≤ 256 bytes

These are deliberately bounded. A graph traversal can touch a lot of data; a small VM should not discover that through an unbounded request.

What it does not do

  • No full Cypher write surface. There is a read-only Cypher subset.
  • No cross-database traversal; edge endpoints must resolve in the same database.
  • No arbitrary subgraph matching or A*.
  • No graph operations over the MongoDB wire protocol; use HTTP/JSON.
  • One graph definition per node collection.
  • No distributed graph partitioning.

If the product is a graph database, use a graph database. If relationships are a feature next to documents, keeping them in the same engine can remove a pipeline and a second backup.

The graph guide covers configuration, filters, temporal edges, rebuilds, and the exact budgets.

All engineering notes →Read the docs