
- 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.
References and further reading
- 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