Skip to content
Size-Tiered Compaction (Cassandra)
step 1/3

Reading — step 1 of 3

Size-Tiered Compaction (Cassandra)

~2 min readCompaction Strategies

Size-Tiered Compaction (Cassandra)

Size-tiered compaction (STCS) is the simplest strategy: when N SSTables of similar size accumulate, merge them all into one larger SSTable. Repeat at the next tier when N of those accumulate. Cassandra has used this since version 0.

The Algorithm

python

A "tier" is informal — it's just a group of files that happen to be the same size. With min_count = 4:

  • Flush 4 memtables → 4 small SSTables → STCS sees 4 of similar size → merge into 1 medium SSTable.
  • After 4 more flushes → 4 small + 1 medium = STCS sees 4 small, merges to 1 medium. Now have 2 medium.
  • After 16 total flushes → 4 medium → merge into 1 large.
  • And so on.

Properties

  • Low write amplification. A byte is rewritten roughly once per tier it advances through. With log4(N) tiers for N files, WA ≈ log4(N).
  • High read amplification. Worst case: a query checks one SSTable per tier — log4(N) for negative lookups, and the bloom filter doesn't help against false positives that ARE present somewhere.
  • High space amplification. Until a tier fills up and merges, obsolete versions sit around. STCS can have 2x the live data size on disk during periods of heavy writes.
  • Bursty compaction. When a top-tier compaction runs, it merges potentially hundreds of GB at once. Big I/O storm; can stall reads.

Where It Wins

  • Write-heavy workloads where read latency tolerance is loose (Cassandra's primary target: time-series, event logs).
  • Append-mostly workloads with few updates/deletes (less benefit from aggressive merging).
  • Operationally simple — only one tunable (min_count).

Where It Loses

  • Read-heavy workloads suffer the log(N) tier penalty.
  • Update-heavy workloads pay the space amp cost.
  • Tail latency is bad — compaction storms cause P99 spikes.

Cassandra's Tunables

min_threshold: 4         # min SSTables per size class before compacting
max_threshold: 32        # max SSTables to compact in one job
bucket_low: 0.5          # tolerance below average size
bucket_high: 1.5         # tolerance above average size

bucket_low and bucket_high define when files count as "same size."

Why Cassandra Defaulted to STCS

Cassandra was designed for write-amplification-sensitive workloads on rotational disks where every write hurt. STCS's lower WA was critical. Modern Cassandra clusters often switch to Leveled for read-heavy column families and TimeWindow (a STCS variant) for time-series.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…