How does an HNSW index handle deletes and updates under a heavy write workload?
Deletes leave tombstoned nodes in the graph (still traversed, filtered from results). Heavy churn bloats memory, slows queries, and degrades recall.
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.
Detailed answer & concept explanation~6 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 min: why tombstones rather than real deletes + three failure modes (memory, latency, recall) + compaction strategies + DiskANN as an improvement + 2026 vendor maintenance patterns + monitoring rubric.
| Operation | What HNSW does internally | Visible cost |
|---|---|---|
| Delete | Sets tombstone bit; node stays in graph | RAM and traversal cost until compaction |
| Update | Tombstones old, inserts new with fresh edges | Doubles per-vector storage until compaction |
| Insert (no churn) | Standard HNSW build: pick M neighbors via greedy descent | Comparable to ground-up build cost per vector |
| Insert (heavy churn) | Picks neighbors from a graph polluted with stale nodes | Recall degradation over time |
| Compaction / rebuild | Drop tombstones, repair edges, or build fresh graph | Expensive 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.
- Weaviate provides async deletes with an explicit `flush` API for batch jobs; production teams typically schedule daily flushes during off-peak hours.
- Milvus uses a segment-based architecture similar to LSM-tree compaction: sealed segments are immutable, updates create new segments, a background compactor merges and reclaims tombstones.
- Microsoft's FreshDiskANN paper (Singh et al., 2021) describes the Vamana variant that handles streaming inserts and deletes with bounded recall degradation, the foundation of several 2026 disk-based ANN systems.
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?
QWhat is the cost of a full HNSW rebuild for 100M vectors?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
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.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.