(smollerGraph)

smollerGraph: Building smollerGraph: A Graph Database from Scratch

A graph database, from the bytes up.

We're going to build a small graph database from scratch in C++: how it keeps nodes and relationships on disk, how it follows them from one to the next, and how a Cypher query becomes a plan that runs, measured against Neo4j and Kùzu, on the way to a knowledge graph that mvGPT can ask for facts.

  1. (pages)
  2. (records)
  3. (hops)
  4. (cypher)
  5. (plans)
  6. (transactions)
  7. (knowledge)
Down the food chain, two hops from the red fox
MATCH (:Animal {name: 'Red fox'})
      -[:EATS*2]->(food)
RETURN food.name
food.name
"Clover"
"Wheat"

Watch the seriesRead the codeAbout

Episodes

  1. FastRP node embeddings in a graph database

    Node embeddings in smollerGraph with FastRP, as Neo4j's Graph Data Science library computes them, the most similar nodes by cosine, embeddings kept on disk, and a page that draws a node's nearest.

    22 min

  2. Dijkstra's algorithm in a graph database

    Weighted relationships and cheapest paths in smollerGraph, with Dijkstra's algorithm and a priority queue, then from both ends, Kùzu's WSHORTEST in Cypher, and weights on the page.

    28 min

  3. Shortest paths in a graph database

    Shortest paths in smollerGraph, with a breadth-first search that keeps each node's parent, then two of them that meet in the middle, shortestPath in Cypher as Neo4j writes it, and a path drawn on the page.

    34 min

  4. Reverse traversal and query planning

    Relationships followed both ways in smollerGraph, with labels and types as tokens to make room for a second chain, Cypher that points left, plans that start from a name, and a fair benchmark in Cypher.

    40 min

  5. Canvas vs SVG for drawing a Wikidata graph

    Mammals and birds from Wikidata in smollerGraph, with room in its records for real names and a label, and a page that draws what a query returns on a canvas, measured against SVG.

    42 min

  6. Property graph storage and WHERE in C++

    Properties for smollerGraph's nodes and relationships, in a chain of records on disk, loaded from facts, asked about with WHERE, and shown in the inspector.

    38 min

  7. Deploying a graph database to a VPS with Docker

    smollerGraph on a VPS, sent over SSH and run with Docker Compose, with Caddy serving the page in front of the database.

    9 min

  8. Writing a Cypher query parser and planner in C++

    A subset of Cypher for smollerGraph, from tokens to a parser, a plan and its rows, in sg query and in the UI.

    28 min

  9. B+ tree index in C++ to find a node by name

    An index on names for smollerGraph, a B+ tree in pages through the buffer pool, so opening a graph no longer reads each node.

    21 min

  10. Database buffer pool in C++ to keep pages in memory

    A buffer pool for smollerGraph, with frames, a page table, pins, dirty pages and the clock, and what it does to a million relationships.

    22 min

  11. Graph visualization in the browser with D3.js

    cpplint, clang-tidy and Abseil's Status for smollerGraph, then a UI, with sg serve answering HTTP and a page that draws the graph with D3, walks it a hop at a time, and shows each node's record on disk.

    49 min

  12. Graph database benchmark of Neo4j vs Kùzu

    A first benchmark on a million relationships, with the same two-hop question asked of smollerGraph, Neo4j and Kùzu.

    20 min

  13. Graph database in C++ with pages on disk

    The graph moves from memory into files of 4 KiB pages, with fixed-size records for nodes and relationships, so it outlives the program.

    29 min

  14. How graph databases like Neo4j and Kùzu work

    Before we build one in C++, why graphs, where the series is heading, and how Neo4j and Kùzu store a graph and run a query.

    33 min