I come from a very large enterprise where standard open-source Active Directory security tools can sometimes struggle to handle the volume of data. When your BloodHound data is tens of gigabytes of JSON, running more interesting queries with longer paths is just not feasible. This is what I wanted to try to tackle, so my engineering team (Claude) and I created BloodTrail.
TL;DR#
- BloodTrail is a proof of concept: an in-memory graph engine that sits underneath BloodHound CE as a DAWGS driver. BloodHound itself barely changes, and PostgreSQL stays the source of truth.
- On a graph of about a million nodes, every query BloodHound ships plus a pile of adversarial ones went from 85.6 seconds to 7.9 seconds in total. The most impressive difference is for “Shortest paths to Azure Subscriptions”, which went from 49 seconds to 63 milliseconds. All this on a standard laptop, not high-end hardware.
- It costs memory (1.92 GiB against 1.21 GiB) and ingest gets 25–40% slower.

Why It’s Slow#
BloodHound has always been one of my favorite tools when it comes to assessing Active Directory security (both for offense and defense). When I started using it, it was still just a portable executable that connected to a Neo4j database and was fairly slow for big graphs. Then SpecterOps drastically modernized it and we got BloodHound Community Edition running in containers with an API, user management and PostgreSQL, and it was already faster. Unfortunately, for my environment it was still not fast enough without throwing money at the problem and getting beefier hardware, and that’s mostly because of how general-purpose databases like PostgreSQL work and how AD graph data looks.
Here is one of the queries BloodHound ships, “Shortest paths to Domain Admins”, trimmed a little:
MATCH p=shortestPath((t:Group)<-[:Owns|GenericAll|GenericWrite|WriteOwner|WriteDacl|MemberOf|
ForceChangePassword|AllExtendedRights|AddMember|HasSession|GPLink|AllowedToDelegate|
... |SpoofSIDHistory|AbuseTGTDelegation*1..]-(s:Base)) // [1] [2]
WHERE t.objectid ENDS WITH '-512' AND s<>t // [3]
RETURN p
LIMIT 1000- At
[1],*1..means any number of hops. No upper bound at all. (The PostgreSQL backend quietly caps it at 15.) - At
[2], the list of edge kinds the search may follow. All 64 of them. With that many allowed, nearly every edge in the graph qualifies. - At
[3], the target: the group whose objectid ends in-512, which is Domain Admins.
Now add hub nodes. Domain Users contains every user in the domain, and Authenticated Users and Everyone are much the same. One hop from any of them and your search frontier (the set of nodes reached so far) is the whole domain.
On the PostgreSQL backend, DAWGS (the layer between BloodHound and its database) turns a query like this into SQL that searches one ring at a time. Every step outward is a fresh round of SQL: plan it, run it, write the new frontier into a temporary table, repeat.
PostgreSQL isn’t bad at its job, it’s just not made for heavy graph workloads.
On my test graph, “Shortest paths to Azure Subscriptions” took 49 seconds. BloodHound’s own sizing guidance for environments above 50,000 users is 96 GB of RAM and 12 CPU cores. These days the RAM is a bit too expensive for that…
However, if we keep just the bare minimum of information about the graph in memory, use that to run traversals and queries, and leave the database to hold all the additional data, we can fit very large graphs in memory with good performance. So I wanted to explore how to do that with BloodHound.
The bare minimum turns out to be very small. A path search needs to know which nodes exist, what kind each one is, and for every edge where it starts, where it ends and what kind it is. We only need to keep the skeleton in memory, and all additional heavy data like descriptions and other properties can continue living on disk in PostgreSQL. Packed into a CSR layout (compressed sparse row: one long array of edges sorted by where they start, plus one array saying where each node’s edges begin), a graph of 5 million nodes and 50 million edges comes to about 0.6 GB, and a single CPU core walks every edge of it, a full breadth-first search, in 857 milliseconds.
How It Plugs Into BloodHound#
My first idea was to build my own thing to replace BloodHound: a standalone, very fast path finder. After about 30 seconds of thinking, that idea went out of the window. BloodHound isn’t just a graph with a UI on top. It’s ingest, roughly 12,000 lines of AD analysis that derives edges like the ADCS escalations, tagging, a user model and an API. That’s years of work by people who know Active Directory far better than I do. Trying to constantly keep up with that by myself would have been too painful.

So instead I decided to augment BloodHound. It talks to its database through DAWGS, SpecterOps’ graph library, and DAWGS picks its backend by driver name, so BloodTrail is simply another driver.
flowchart LR BH["BloodHound CE
UI, ingest, analysis"] --> D["DAWGS"] D --> BT["bloodtrail driver"] BT -->|"reads it can answer exactly"| R[("in-memory replica")] BT -->|"everything else"| PG[("PostgreSQL")] BT -.->|"every write, first"| PG
The change to BloodHound itself is two small edits in two files. The main one is a new case in the switch that picks a backend:
case bloodtrail.DriverName:
slog.InfoContext(ctx, "Connecting to graph using BloodTrail")
connectionString = cfg.Database.PostgreSQLConnectionString()
pool, err = dbpool.NewDawgsPool(cfg.Database)
if err != nil { return nil, err }The other widens a type check in one migration, so it still recognizes the PostgreSQL graph sitting underneath BloodTrail. That’s the whole change BloodTrail makes to your existing BloodHound when you install it. Ingest, analysis, the UI and the API are all untouched, and a build script applies the patch to an upstream release and builds a normal image with BloodHound’s own Dockerfile.
BloodHound can’t load drivers at runtime, so “just a driver” still means a rebuilt image for every upstream release.
Keeping It Correct#
Since the graph traversal is now done in memory, the speed was there almost immediately. Everything in BloodTrail since has gone into a harder question: is the answer actually right? A wrong answer in a security tool is unacceptable.
Every read that arrives through BloodHound’s read transactions is offered to three serving paths: a shortest-path engine, a recognizer for the structural queries BloodHound’s own code issues behind entity panels and tagging, and a Cypher interpreter. Each one answers only if it can reproduce exactly what PostgreSQL would return; anything less, and the query gets passed to the PostgreSQL driver, like in stock BloodHound. The planner is default-deny: it holds a list of query shapes it understands and passes on everything else.
Writes are harder, because the in-memory replica has to stay correct as the real data changes under it. The tempting approach is to replay each write against the copy: treat it as an upsert, merge the properties if the node exists, create it if it doesn’t, and so on. But in this case we would likely end up reimplementing PostgreSQL’s rules for upserts, cascading deletes and half-failed batches, and it quickly gets way too complicated.
I didn’t really want to reinvent the wheel (says the guy reimplementing a graph database), so I chose an easier path instead. While a write runs, BloodTrail notes only which keys the write touched. Once PostgreSQL commits, it reads those keys back on a separate connection and copies whatever it finds: if the row is there, that’s its new state; if it’s gone, it gets marked as deleted. The complexity of whether a node was deleted directly, deleted by a cascade, or never created because a batch failed halfway through is gone.
BloodTrail doesn’t even try to follow the few writes that can’t be handled that way, such as mutating Cypher and arbitrary delete criteria. Those writes flip the whole engine into a fallback mode where every query goes to PostgreSQL while the replica rebuilds in the background.
In order to ensure correctness, I check all of it against PostgreSQL at every level: unit tests and Go’s race detector over the engine, 200 randomly generated Cypher queries run against both backends and compared row for row, the same comparison across every query BloodHound ships, and an end-to-end test that installs the real driver into a real BloodHound and checks the answers it hands back.
Benchmarks#
The testing setup is two complete BloodHound CE v9.7.0 installs on the same machine and the same graph, one stock on PostgreSQL and one with BloodTrail. The graph is synthetic, about a million nodes and 2.4 million edges across four AD domains and an Entra tenant, generated as SharpHound output and uploaded through BloodHound’s normal ingest. The machine is my MacBook Pro with M3 processor, with Docker given 12 CPUs and 7.65 GiB of RAM (against the 96 GB in BloodHound’s own sizing guidance).
The 182 queries are every query BloodHound ships with, plus some adversarial ones I wrote specifically to make BloodTrail struggle.
| Query | Stock | BloodTrail | |
|---|---|---|---|
| Shortest paths to Azure Subscriptions | 49,192.6 ms | 63.4 ms | 776× |
| Shortest paths from Owned objects | 3,385.9 ms | 22.5 ms | 150× |
| Shortest paths to Domain Admins | 1,754.0 ms | 99.1 ms | 18× |
| Kerberoastable users with most admin privileges | 2,525.8 ms | 446.9 ms | 5.7× |
| All 182 queries | 85.56 s | 7.87 s | 10.9× |
Not every query wins, and I should be straightforward about the losses. 58 of the 182 are slower with BloodTrail, the worst by 1.47×. But it is important to note that every one of them is a query both setups already answer in about 20 milliseconds, so the difference is not really noticeable. Break one of those requests apart and the actual graph work is one to two milliseconds on either side; about 18 ms is BloodHound’s own request handling (parsing, rewriting, complexity checks, building the response), which no driver can touch, and the rest is the cost of a process carrying an extra gigabyte around. At that scale the numbers are noisy, too: re-running the 22 worst-looking ones 15 times each turned 9 of them into wins.
The costs that actually matter are memory and writes. Memory is 1.92 GiB resident against 1.21 GiB in this run. Ingest is slower too: in a separate test, uploads took 25–40% longer, because every write now updates the replica as well. BloodHound is written to much less often than it is read from, so from my perspective that’s a sacrifice I can easily make.
These numbers were measured with BloodTrail v0.1.1. The full table, the caveats and how to reproduce it all are in BENCHMARK.md.
A Proof of Concept#
BloodTrail is a proof of concept. I want to be upfront about that, because the repo has an installer, a whitepaper and a lot of tests, and that can look like a product. It really isn’t one (at least right now).
What it proves is that with a bit of creativity we can always try to improve even well-established tools like BloodHound. This was made to inspire future improvements and encourage experimentation. AI makes it very cheap to produce code, so throw all your crazy ideas at it and try to make things you use a tiny bit better.
If you want to try out BloodTrail, installing and rolling back are one line each, run from the directory that holds your BloodHound compose file:
curl -fsSL https://github.com/MihhailSokolov/BloodTrail/releases/latest/download/install.sh | sh -s -- install
curl -fsSL https://github.com/MihhailSokolov/BloodTrail/releases/latest/download/install.sh | sh -s -- rollbackThe installer shows what it found and asks before changing anything, and it backs up the database, the compose file and .env first.
NB! Do be mindful that this is an experimental tool if you ever want to use it in production.
Wrapping Up#
The trick in this post isn’t new. I first used it on Maven call graphs, where we kept the serialized graphs in memory rather than in a graph database because that is what made them fast, and people who build graph systems have known it for far longer than that. In short, it is always about finding the right tool for the job - or creating one yourself.

Everything is on my GitHub: the code, the benchmarks with instructions to reproduce them, and a long whitepaper, which explains how everything works in a slightly less entertaining style. Enjoy!