Your database is getting slower. But your write traffic hasn’t increased. What’s happening?

Distributed Systems
System Design
RocksDB
Databases
Performance Engineering
How compaction debt builds up in LSM-tree storage engines and which RocksDB metrics can reveal it before latency spikes.
Published

November 28, 2026

Tech Blog · 简体中文

The answer may be Compaction Debt — a hidden performance problem in databases built on LSM-Trees, such as RocksDB and Cassandra.

The interesting part? Your database may have been accumulating this problem for hours before users notice anything.

1. LSM-Trees: Fast writes come with deferred work.

Instead of updating records in place, LSM-based storage engines buffer writes in memory and flush them into immutable SSTables on disk.

This turns many random writes into sequential writes, improving write performance.

But over time, SSTables accumulate overlapping key ranges, outdated versions, and deletion markers.

The database must periodically merge these files through compaction.

Essentially, LSM-Trees make foreground writes cheaper by deferring part of the work to the background.

2. Compaction Debt: When deferred work accumulates.

Imagine a RocksDB instance:

  • Application write throughput: 100 MB/s
  • Write amplification: 10x
  • Required physical write throughput: 1,000 MB/s
  • Available disk write bandwidth: 800 MB/s

Under these simplified assumptions, the storage engine cannot sustain the required physical write workload.

Initially, everything may appear healthy.

Writes are still accepted. Latency remains low.

But pending compaction work keeps accumulating.

Eventually:

  • More overlapping SSTables increase read amplification.
  • Obsolete data increases space amplification.
  • Background compaction competes with foreground requests for I/O.
  • The storage engine slows down or stalls writes.

Your P99 latency spikes even though application traffic hasn’t changed.

Yesterday’s fast writes have become today’s expensive operations.

3. Why not simply increase compaction throughput?

Because compaction itself consumes resources.

Aggressive compaction reduces accumulated debt but competes with foreground operations for CPU and disk bandwidth.

Conservative compaction protects immediate request latency but risks accumulating more debt.

This creates a fundamental tradeoff between:

  • Write Amplification: How much physical data must be rewritten?
  • Read Amplification: How much work is required to retrieve a record?
  • Space Amplification: How much extra storage is occupied?

Optimizing one often comes at the expense of another.

4. What should engineers monitor?

In RocksDB, useful indicators include:

  • Estimated pending compaction bytes
  • Level-0 SSTable count
  • Write amplification
  • Write stall duration
  • Disk bandwidth utilization

The trend matters more than any isolated measurement.

A steadily growing compaction backlog is an early warning that the current workload may be unsustainable, even when request latency looks healthy.

The key takeaway:

LSM-Trees don’t eliminate write costs. They redistribute those costs across time.

A database’s sustainable write throughput is determined not just by how quickly it accepts writes, but by how quickly it can complete the background work those writes generate.

Fast writes are not necessarily cheap writes. Sometimes, you’re just borrowing performance from the future.

Have you encountered compaction-related latency spikes in production?