Dogfooding a graph database with a live Bluesky feed

How a live Bluesky feed on a graph database, combining sustained writes, parallel queries, in-engine modules and analytics, surfaced engine defects benchmarks miss, each fixed upstream.

October 20233 min readStoragePerformanceVerification

Two clusters of broken arcs, graphite and dull blue, sit opposite each other across pale open chalk with a barely tinted ochre plane between.
On this page
  1. Parallel ranking and in-engine scoring
  2. Sustained writes alongside graph analytics
  3. Bulk deletes and memory retention
  4. From live failures to upstream fixes

Every database ships with test suites and benchmarks that pass, and they exercise the access patterns the engine’s authors had in mind. Live workloads rarely stay inside a single benchmark’s envelope. Customers run continuous ingestion, concurrent reads, custom code inside the engine, and background analytics against the same dataset, and they hit the remaining defects in production. Synthetic load generators widen coverage, yet they still reproduce only the failure modes someone already thought to model.

Catching those interactions first takes dogfooding with a real workload: becoming the database’s zeroth customer, running a service with active users and live external data where exposing engine failures is the point. While working at Memgraph, an in-memory graph database that uses the Cypher query language, I put this into practice by building Home+, a personalized feed for Bluesky using its feed-generator kit. Bluesky had just opened custom feeds, and I started within days of the kit’s release. Home+ subscribes to the AT Protocol firehose, the public stream of every post, like, and follow on Bluesky’s open protocol, writing hundreds of social events a second into Memgraph while answering per-subscriber ranking queries and running community detection over the same graph. Each of the five upstream issues Home+ surfaced traced directly to an ordinary design choice in the feed.

Parallel ranking and in-engine scoring

A chronological feed breaks down once a user follows more than a few dozen accounts, so Home+ assembles each subscriber’s timeline from three sources: posts from accounts they follow, posts those accounts liked, and posts from their detected community. The service runs those three Cypher queries in parallel, scores each candidate list with a Hacker News-style time decay of likes over post age raised to a power, and blends the results with a weighted round-robin that deduplicates posts across the three lists.

Hauling large candidate sets across the wire to score them in application code wastes serialization and network latency, so scoring belonged inside Memgraph as a query module. Implementing the decay calculation as a Python query module cost about 800 ms per call, which ruled it out for interactive feed requests. Moving the same logic into a 45-line C++ query module eliminated that call overhead and immediately exposed a worse defect: dispatching the three parallel ranking queries against the C++ module could crash the database server. C++ query modules were not thread-safe, a race a sequential microbenchmark of the module never triggers.

Sustained writes alongside graph analytics

Populating the community signal meant running community detection over a graph taking hundreds of firehose writes per second. That overlap hit two separate limits in the engine. Online community detection exhausted available memory once the graph reached roughly a million nodes and six million edges, a small footprint for a live social graph. Running community detection in Memgraph’s analytical mode instead produced unresolvable transaction conflicts whenever concurrent firehose writes were active.

To keep Home+ serving subscribers around those limits, writes pass through a defensive queue that retries across transaction conflicts and database restarts and catches up missed firehose events from a persisted cursor after downtime. The same queue provides a pause switch so community detection can run without concurrent write contention, then drains the queued backlog once the pass finishes.

Bulk deletes and memory retention

An in-memory database fed by an unbounded firehose cannot grow indefinitely, so Home+ periodically prunes older data. When the graph reached 56 million nodes, I ran a bulk delete to remove 16 million older nodes and reclaim RAM. Resident memory climbed from 12 GB to 18 GB instead, and the server ran out of memory trying to free it.

Few database benchmarks build a graph to tens of millions of live nodes and then delete more than a quarter of it. Reporting that large deletes ran out of memory would have left the engine team guessing at the allocator behavior, so I filed the issue with Home+‘s daily database dump and the exact Cypher delete query. Given a deterministic local reproduction, Memgraph’s engineers isolated the retention problem and added garbage collection with periodic jemalloc purging so freed pages returned to the operating system.

From live failures to upstream fixes

Client-side workarounds like pausing ingestion keep subscribers online, yet absorbing engine bugs in application code defeats the point of dogfooding. Every issue Home+ hit went upstream to Memgraph’s issue tracker as a self-contained reproduction: the live graph dump when scale mattered, the exact query or C++ module, and the concurrent read or write pattern needed to trigger it. Memgraph’s engineers fixed or resolved all five issues upstream.

Chris Chabot, October 2023