What is Cassandra's compaction and its types?

Answer

Compaction is Cassandra's background process that merges multiple SSTables into fewer, optimized SSTables — removing tombstones, merging duplicates, and reducing read overhead. Three main compaction strategies: STCS (Size-Tiered Compaction Strategy): default. Groups similarly-sized SSTables and merges them when thresholds are met. Good for write-heavy workloads. Disadvantage: temporarily doubles disk space during compaction; reads can be slow with many SSTables. LCS (Leveled Compaction Strategy): organizes SSTables into levels with fixed sizes. More predictable read performance and less space amplification. Best for read-heavy or mixed workloads. Higher write amplification (more I/O during compaction). TWCS (Time Window Compaction Strategy): designed for time-series data with TTLs. Compacts data within a time window together — enables efficient SSTable expiration when all data in a window is expired. Best for time-series data with consistent TTLs. Choose the strategy based on your read/write ratio and data access patterns.