Zenaique

How does an HNSW index handle deletes and updates under a heavy write workload?

Flashcard·Medium·4.0 · 0·~30s·Asked atQdrantUnityVellum·Relevant atMicrosoftNVIDIA
Attempt it
TL;DR

Deletes leave tombstoned nodes in the graph (still traversed, filtered from results). Heavy churn bloats memory, slows queries, and degrades recall.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine a phone book where every entry is connected by little arrows to a few similar entries. When someone moves out, you do not actually rip the page out (that would shred all the arrows pointing to that page and you'd have to redraw them). Instead, you put a sticker on their entry that says 'gone'. People searching the phone book still wander past their entry, follow their arrows for a few hops, then realize the entry is marked and move on. The book gets thicker with stickered entries over time, paths get muddled, and eventually a librarian has to sit down and rebuild the whole book to make searches fast again.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

HNSW is a beautifully simple data structure when the corpus is static. The complications come from how it handles change. The standard HNSW build algorithm assumes you have all the vectors in hand and constructs the graph in one pass. Real production indexes never have that luxury: documents arrive, get updated, get deleted, embedding models change. How HNSW handles those changes determines whether the index degrades silently or stays healthy.

This question is about a specific failure mode that does not appear in academic ANN benchmarks (which are static) but bites every production HNSW deployment eventually.

Why deletes are tombstones

An HNSW graph stores, for each node, a list of M neighbors per layer. Deleting a node means removing it from every neighbor list that mentions it. With M = 32 neighbors per layer and 2-3 layers per node on average, that is 64 to 96 incoming-edge references to find and repair for each deletion. Worst case, repairing requires a scan; with a reverse-index it is bounded, but the repaired neighbors then need new neighbors to replace the deleted one, which triggers more partial rebuilds.

Doing this synchronously on every delete kills write throughput. So every production HNSW implementation uses tombstones: a 1-bit-per-node flag that says 'logically deleted, do not return in results'. The node, its vector, and its edges remain in memory and remain part of the graph. Searches still traverse through tombstoned nodes; they are filtered only at the top-K collection step before returning to the caller.

This trades O(1) per-delete cost for deferred maintenance. Every tombstone is a small lien against future compaction. Without compaction, the liens accumulate until the graph degrades.

Updates are tombstone-plus-insert
The three failure modes under heavy write workloads
Compaction and the production maintenance pattern
Why DiskANN / Vamana does better
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.
OperationWhat HNSW does internallyVisible cost
DeleteSets tombstone bit; node stays in graphRAM and traversal cost until compaction
UpdateTombstones old, inserts new with fresh edgesDoubles per-vector storage until compaction
Insert (no churn)Standard HNSW build: pick M neighbors via greedy descentComparable to ground-up build cost per vector
Insert (heavy churn)Picks neighbors from a graph polluted with stale nodesRecall degradation over time
Compaction / rebuildDrop tombstones, repair edges, or build fresh graphExpensive but restores all properties

Real products, models, and research that use this idea.

  • Pinecone runs continuous background optimization on managed indexes; users observe the effect on recall and memory without configuring the compaction directly.
  • Qdrant exposes `optimizers_config.deleted_threshold` and related knobs; compaction triggers automatically when tombstone ratios cross those thresholds.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QWhy does graph quality degrade even with no deletes, just heavy inserts?
A

New inserts pick neighbors greedily from the existing graph; the greedy algorithm tends to over connect to high degree nodes (hub formation). Periodic rebuild rebalances the degree distribution.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Assuming HNSW deletes are free because they don't change the graph structure. Tombstones are cheap to write but expensive to live with, they cost RAM and traversal hops on every query forever, until you rebuild.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Tombstone mechanism: logical delete, physical node persists

  • Update = tombstone-old + insert-new (no in place update)

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
HNSW vs IVF, when…
Flashcard·Medium