
- Runs in the background without blocking incoming writes, keeping the system responsive during cleanup.
- Reduces the number of segments a query must scan, lowering per-query overhead and improving retrieval speed.
- Is tunable: administrators can adjust merge frequency, size thresholds, and merge policies to trade off write throughput, storage efficiency, and query latency.
Background merging greatly reduces query overhead, but you should tune merge frequency and thresholds to match your workload. For write-heavy systems, favor less aggressive merges to keep write latency low; for read-heavy systems, more aggressive merging improves query performance. Consider metrics such as segment count, average segment size, and query latency when tuning.
Aggressive merging can cause temporary CPU and IO spikes that impact overall throughput. Schedule heavier compaction during off-peak hours and monitor system load to avoid introducing instability.
- Merge small pieces (compaction) is ideal when fragmentation from frequent small writes causes high query overhead but the index structure itself remains valid.
- Full rebuild/reindex is appropriate when you need to change indexing structure (e.g., new vector codec, different clustering parameters, or schema changes), or when compaction alone cannot recover desired storage or performance characteristics.
| Strategy | Use Case | Pros | Cons |
|---|---|---|---|
| Merge / Compaction | Reduce fragment count from write-first ingestion | Lowers IO & metadata overhead; incremental; keeps system online | Needs careful tuning; can cause IO spikes during merges |
| Full Reindex / Rebuild | Change index structure or recover from heavy fragmentation | Produces optimal layout and allows structural changes | Resource-intensive; may require downtime or heavy background resources |
- Log-Structured Merge Trees (LSM) — background on compaction strategies used in many storage engines
- RocksDB Compaction — practical implementations and tuning examples
- Vector search architectures and segmenting — examples and design discussions for vector databases