(smollerGraph)
  • Episode 17
  • 13 min

Architecture decision records for our graph database

Architecture decision records for smollerGraph, from its first episode's adjacency to last time's docs, each with what forced the choice, what lost to it and what it costs, and how a team proposes, accepts and supersedes them.

15 November 2026 · Watch on YouTube

After sixteen episodes, smollerGraph's code says what the database does and each commit what changed, but the reasons behind its choices are in the videos, and the repository keeps none of them. So it gets a folder of architecture decision records, after Michael Nygard's format: one for each choice that would be costly to undo, with the context, the decision, the alternatives considered and the consequences. We go through how a team uses them, proposed in a pull request, accepted as it's merged and superseded instead of rewritten, and then through some of smollerGraph's own, from how it keeps a node's relationships to the record that stopped the races against Neo4j and Kùzu. And the records are published with the API docs.

Topics: Tooling and deployment

The code

Each step on screen is a tag in the database's repository. The code at the end of the episode is ep017/end.

  1. 3:10ep017/step-1Our recordsBrowseChanges
  2. 10:56ep017/step-2With the API docsBrowseChanges

Transcript

Intro

0:00 Hi, and welcome to episode seventeen, where we're not adding anything to the database. Instead, we're going to write down why it's built the way it is, one decision at a time. First, a quick look at what we'll have by the end.

0:15 By the end, the API docs have a page of decision records, twenty-two of them, with an index that gives each one's status and the episodes it came from. Two have been superseded, such as measuring each change against Neo4j and Kùzu, whose row links to the record that replaced it. From episode twelve, we build vanilla versions of what those two offer, and stop racing them.

0:37 If you're new here, the series' website has more on the project. It links to the code on GitHub, where each step of each episode is a tag you can check out, and each episode has a page, with its chapters and the code it changed.

Last time

0:51 A quick reminder of where we left off, first. Last time, Doxygen made API docs out of the comments already in our headers, with a filter that gives each comment the third slash it reads. A stage in the Dockerfile builds them on a clean Ubuntu, and CI publishes them on GitHub Pages, from the public repository. Those docs say what each class and function does, a page for each. What they can't say is why the database is built this way, and that's what we're going to fix today.

Today

1:20 After sixteen episodes, the code says what smollerGraph does, and each commit says what changed in its step. The reasons, though, are in what I said in the videos, which nobody reading the repository is going to sit through. On a team, they'd be in a chat thread, the notes of a meeting, or the head of whoever was there, and that's the part that gets lost first. So we're going to write a record for each choice that would be costly to undo, which is called an architecture decision record, or an A D R. Each one says what forced the choice, what we picked, what else we weighed, and what it costs us. And once a record is accepted, it isn't rewritten. Changing our minds means a new record that supersedes the old one.

On a team

2:01 You're quite likely to meet this practice at work, under this name or another. Michael Nygard described the format in a blog post in 2011, and some teams write longer documents that do this job, called design docs, or R F Cs, requests for comments. On a team, a record can start before the code, or come with the pull request that makes the change. Either way, it's proposed in a pull request, and the review is where the team argues about the choice, in writing, while changing it costs a comment and not a rewrite. I like this part the most, as people who'd lose the argument in a meeting can still make their case in a review, with numbers. When the pull request is merged, the record is accepted, and the team builds on it. If you join a team that keeps them, your best bet is to read them in your first week, before you ask why something is the way it is. And if you disagree with one, you propose a new record that supersedes it, saying what's changed since. If your team keeps none, I'd start with the next decision, and not try to write up the last hundred. We're doing it the hard way today, after sixteen episodes, while the reasons are still in the videos.

Our records

3:10 Our records get a folder in the docs, called decisions, with a README on what they are, and why we keep them. They follow the format Michael Nygard described, kept short, with a section he didn't have, for the alternatives. The twenty-two we have were written today, from what episodes one to sixteen said and what their commits hold. Where an episode gave no reason for a choice, the record says so. I'd hold that line, as a reason made up after the fact is worse than a gap. The README gives four reasons to keep them, and most of them point at records of ours. The why outlives the people who knew it, such as why our pages are four kibibytes. Someone new can read them top to bottom, and get the architecture in the order it was built. And a settled question, such as why we don't let the operating system cache our pages, already has an answer. A record is for a choice that's costly to reverse, such as how the graph sits on disk, or the query language. A change that one commit could undo needs none, and I'd keep it that way, as a folder of a hundred small records is one nobody reads. Each record has a status, the context, the decision, the alternatives considered and the consequences. An alternative goes in if somebody weighed it, or if it's the obvious one, marked as not weighed. Then there's a section on working on them with others, as we just went through. It has a line I like a lot. A question a newcomer asks that no record answers is a record that's missing.

Storage

4:43 The records go in the order the choices were made, and we'll start with three about how the graph sits on disk. Record three is about keeping each node's relationships beside it. Episode one looked at two ways of doing that. Kùzu keeps columns, with its adjacency in compressed sparse row form, and we leaned towards records that point at each other, like Neo4j's, as it's the simplest way to see what a hop costs. A new relationship goes at the front of its node's chain, which is two writes, however long the chain is. A crash between those two writes leaves a relationship that no chain points to. Up to episode sixteen, there are no transactions or write-ahead log to stop it. Record seven is the pages, of four kibibytes each. The reason is the hardware, as modern disks store data in sectors of four kibibytes, and most file systems hand out space in blocks that size. The Mac these videos are made on has memory pages of sixteen kibibytes, and the record says that no episode has measured that yet. A fixed size also limits how long a name can be, and in episode ten, about two thousand eight hundred of Wikidata's names didn't fit, so a node's record grew to sixty-four bytes. And record eleven is the buffer pool, which keeps pages in memory, with the clock algorithm picking which one leaves. Its alternative is the one people tend to ask about, letting the operating system cache the file, with mmap. Episode five followed a paper by Crotty, Leis and Pavlo that argues against it. With mmap, the operating system decides when a changed page is written, and that gets in the way of a write-ahead log. The pool took a load from about twelve seconds to about one. In exchange, a crash in the middle of a load loses what's in the pool. Again, stopping that is a log's job, and we don't have one yet.

Errors and queries

6:31 Record nine is about how our functions report errors. Our code follows Google's style guide, which doesn't use exceptions. And episode one's reason for returning an error as a value was that it shows up in the function's signature, so a caller can see it has to check. From episode four, a function that can fail returns Abseil's status, a code from a fixed list and a message, so the code that gets an error can tell one kind from another. Its consequences say where we cut a corner. Three failures stop the program instead of returning, such as a page that can't be read once its file is open, which a database meant to run for months would handle more gently. Record thirteen is our subset of Cypher, which goes from text to answers in four stages. The plan's steps take Neo4j's operator names, so that our EXPLAIN reads a bit like theirs. A plan starts from the node that's cheapest to find, by a rule: a name, through the index, then a label, then any node. What lost was picking the start from statistics on the graph, as Neo4j and Kùzu estimate what each start costs. I think a rule was the right place to start, as anyone can tell which node it picks by reading the pattern. With it, a query for the critically endangered pangolins read thirty-three pages, where a scan of the species' label read more than thirteen hundred. And the cost is that each step holds all of its rows in memory, which a bigger graph would run out of memory doing.

Superseded, not rewritten

7:57 Two pairs of records show how a decision changes. Record ten is about drawing the whole graph in the browser, with SVG, and its status says superseded by sixteen, with a link to it. Episode four didn't say why it drew the whole graph, or why with SVG, and the record says so. Its consequences say why it went, as on nearly twenty-two thousand mammals and birds from Wikidata, the page was a tangle of lines, at a few frames a second. So sixteen, from episode ten, draws what a query returns, on a canvas, and no more than five hundred of its nodes. Its alternatives keep what was measured, and at five thousand nodes, the canvas kept up at fifty-nine frames a second, while SVG fell to twenty-three and a half. Past that, the layout is what's slow, as D3 runs it on the page's one thread. And apart from its status line, the old record stays as it was, so someone who finds the SVG page in the history can follow its link on to sixteen.

8:55 The other pair is the one I'd point a new teammate at first. Record eight is about measuring each change against Neo4j and Kùzu, from episode three, and it keeps the numbers. A two-hop walk took about seventy microseconds in ours, against about seven hundred and fifty in Neo4j, and fifteen hundred in Kùzu. Episode three called it not a fair fight, as ours was a function call, while theirs parsed and planned Cypher, through Python, and for Neo4j, over the network to a container. Episode eleven made the race fair, with Cypher on all three sides, and it still said that we're not claiming to be faster than either. So record eighteen supersedes it, and from episode twelve, we build vanilla versions of what Neo4j and Kùzu offer, and stop racing them. Their searches are built for graphs far bigger than ours, with years of engineering behind them, while ours are there to show how a feature works. A feature is measured against our own simpler version of it instead, such as a search from one end against a search from both. Its alternative is going on with the races, as episodes three, five and eleven did.

Outside the database

10:05 One more, from episode fifteen, about where the work happens. Record twenty-one is about training our models outside the database. Neo4j's Graph Data Science library trains a model inside the database, and writes each prediction back to its node. Our graph goes out through our sg program's export, to a script in PyTorch, and the predictions come back through sg load, as facts. It trains on one thread, because with more, a sum can be added up in a different order from run to run, and floats round differently in each order, so each run would train a slightly different network. The record keeps the modest result too, as the network scored zero point seven three four, against zero point seven two nine for a rule written by hand. And my favourite line in it is that the database gained an export and nothing else, so PyTorch stays out of its build.

With the API docs

10:57 The records are going to be published with last episode's API docs. In the CMake file, Doxygen would turn a folder's README into that folder's page, under its files, so we turn implicit directory docs off. Then the docs target takes the decisions README and its folder, after our main README, so each record is a page, and the links between them work there as they do on GitHub. In our main README, a new section points at the records. It says what they hold, a short record for each choice that would be costly to undo, with what else was weighed and what it costs. And it says that the folder explains how to propose one, for anyone who'd like to bring a decision of their own. And writing record eighteen showed that the README's benchmarks section still read as if we raced Neo4j and Kùzu after each change. So a few lines now say that the races stopped at episode twelve, that the comparison script is as episode eleven left it, and where the record is.

What writing them found

12:00 Writing the records after the fact was slow, but it turned up a few things. Some reasons were missing, such as whether we weighed LDBC's own data before writing a generator of our own, and the records say so. Two records name one missing piece as their cost, a crash between two writes and a crash in the middle of a load, which is what a write-ahead log is for. So the records also say what the database is missing. And a section of the README had gone out of date. On a team, you find these when someone tries to write a reason down, which is a cheap time to find them.

Wrap-up

12:32 So, smollerGraph now keeps the reasons for its choices next to its code, a record for each choice that would be costly to undo. On a team, a record is proposed in a pull request, argued over in its review, and accepted as it's merged, and changing a decision later takes a new record that supersedes it. And the records are published with the API docs.

12:53 I'd love to hear how this works where you are. Let me know in the comments whether your team keeps decision records, or design docs, and what it does when one of them turns out to be wrong. If you'd like to follow along, subscribe to the channel. I hope you find this useful, and thanks for watching.