Okay, the user wants me to explain the thought process behind building a compaction strategies catalog for columnar and log stores. Let me start by breaking down what they're actually asking for. They mentioned both columnar and log stores, so I need to cover both areas separately since they have different use cases and mechanisms.
First, I should define what compaction is in general, then dive into why it's important for each type. For columnar stores, I need to consider how they handle batch updates and deletions, like merging smaller files into larger ones and discarding old versions. Maybe mention specific strategies like size-tiered, leveled, and date-tiered.
For log stores, it's about optimizing write-heavy workloads. Here, strategies like time-based compaction, sequence-based, and size-based come to mind. Also, log-structured merge trees (LSM) are key here. I should include hybrid approaches too, since real-world systems often combine methods.
I need to make sure the catalog is structured but not too technical. Tables might help for quick comparison, but the explanation should highlight trade-offs. Emphasize that no single strategy is best—it depends on the workload. Mention examples like Cassandra, Hudi, or Kafka for log stores, and ClickHouse or BigQuery for columnar.
Wait, did I miss any key strategies? Let me double-check. Columnar: size-tiered, leveled, date-tiered, FIFO. Log: time-based, sequence-based, size-based, hybrid. Also, consider special cases like Kafka's log compaction for key-based retention. Should I include delta lakes and streaming systems? Yes, since they blend both paradigms.
Make sure to clarify that columnar compaction is more about query performance and storage efficiency, while log compaction focuses on throughput and recovery. The user might be designing a system or troubleshooting performance, so highlighting decision factors is crucial. Avoid jargon but stay precise. Keep each section concise but comprehensive enough for someone to choose a strategy based on their needs.
Excellent request. Compaction is a fundamental background process in distributed storage systems that reorganizes, merges, and discards data to optimize for read performance, storage efficiency, and system stability. The strategies differ significantly between columnar stores (optimized for analytics) and log-structured stores (optimized for write throughput and immutability).
Here is a structured catalog of compaction strategies for both domains.
Compaction Strategies Catalog
1. For Columnar Stores (e.g., ClickHouse, Apache Druid, BigQuery, Snowflake)
Core Principle: Merge small, immutable files (often in formats like Parquet/ORC) into larger, sorted, and column-pruned files to minimize the number of blocks read during analytical queries. Handles updates/deletes via multi-version concurrency control (MVCC).
Strategy
Mechanism
Primary Goal
Best For
Trade-offs & Notes
Size-Tiered Compaction
Merge smaller files (e.g., <100MB) into medium files, then medium into large files (e.g., >1GB). Triggered when file count/directory size exceeds a threshold.
Write Amplification Control & Simple Merging.
High-volume, append-only ingestion with infrequent point updates. (e.g., IoT logs, clickstreams).
Can create many "levels" of file sizes, leading to read amplification (query must check many files). Simplest to implement.
Organizes files into fixed-size levels (L0, L1, L2...). L0 contains newest, unsorted files. Each level n is 10x larger and fully sorted than level n-1. Compaction merges files from L(n) into L(n+1).
Read Amplification Minimization. Guarantees at most 1 file per key/partition per level.
Point-lookup heavy workloads, frequent updates/deletes on specific keys, systems needing low-latency reads. (e.g., Druid's index_ compaction).
High write amplification during compaction (more I/O). More complex scheduling. Requires careful level sizing.
Date/Time-Tiered Compaction
Partition data by time (day, hour). Only merge files within the same time partition. Old partitions become immutable and never compacted further.
Time-Series Optimization & Low-Latency on Recent Data.
Time-series data where queries almost always filter on time. Recent partitions get compacted (improving writes), old partitions remain read-optimized.
Inefficient for queries spanning many time partitions. Storage overhead if partitions are small.
FIFO / TTL-Based Compaction
Discard entire files older than a configured Time-To-Live (TTL) or based on a fixed retention policy. No merging, just deletion.
Simple Data Expiration.
Event logs, audit trails, caching layers with absolute data lifetime.
Key Columnar Compaction Decision Factors:
Update/Delete Frequency: High → Prefer Leveled.
Query Pattern: Point lookups → Leveled; Full scans → Size-Tiered or Time-Tiered.
Data Freshness SLA: Low-latency on new data → Incremental/Delta.
Core Principle: Convert random writes into sequential writes to an immutable, append-only log (memtable -> SSTable). Compaction merges multiple SSTables to remove duplicates, tombstones (deletes), and obsolete data, while maintaining sorted order for efficient reads.
Strategy
Mechanism
Primary Goal
Best For
Trade-offs & Notes
Size-Tiered Compaction (STCS)
Trigger when number of SSTables of a similar size reaches a threshold (min_threshold). Merge N SSTables into one larger SSTable. Most common default.
High Write Throughput & Simple.
Write-heavy workloads with large, sequential scans. Good for append-only time-series or logs.
Highest Read Amplification (many SSTables to check per query). Highest Space Amplification (until merge happens). Tombstone accumulation risk.
Leveled Compaction (LCS)
Organizes SSTables into levels with strict size ratios (e.g., 10x). Each level contains non-overlapping sorted runs. compaction merges from level i to i+1.
Tombstone Management: High delete rate → LCS (better at purging tombstones quickly).
Operational Stability: Predictable disk I/O → LCS (more uniform). STCS can cause periodic I/O spikes.
3. Specialized & Hybrid Catalog Entries
Store Type
Strategy
Purpose & Example
Streaming Logs (Kafka)
Log Compaction (not file compaction).
Keeps latest value for each key indefinitely. Deletes older records for a key. For changelog topics, state store backups.
Streaming + Batch (Flink, Spark)
Checkpoint & State Compaction.
Compact operator state backend (RocksDB) using built-in LCS/STCS. Additionally, compact checkpointed files in distributed storage (e.g., HDFS, S3) using bucket-level compaction.
Object Storage (S3, GCS)
Lifecycle Rules & Rewrites.
Not automatic compaction. Uses lifecycle policies (expire, transition) or manual jobs (using Spark/Databricks) to compact small files into larger Parquet datasets.
Multimodal Stores (Hudi, Iceberg)
Hybrid Compaction (Copy-on-Write vs. Merge-on-Read).
Hudi COW: Write new files, compact immediately (like columnar). Hudi MOR: Small delta logs compacted lazily into larger Parquet base files (like LSM).
Key-Value Stores (Redis, Aerospike)
Defragmentation / AOF Rewrite.
Not strictly compaction, but reorganizes memory or rewrite Append-Only File to remove expired/deleted entries, reducing fragmentation.
Limited storage: Avoid strategies with high space amplification (STCS) without aggressive thresholds.
What system are you using?
Check defaults first. (e.g., Cassandra: STCS; RocksDB: LCS; ClickHouse: merges based on parts_to_throw_insert and parts_to_delay).
Tune thresholds (min_threshold, max_threshold, level sizes, TTLs) based on your data size, ingestion rate, and query patterns.
Final Recommendation: Start with the system's default strategy for your data model. Use monitoring (compaction pending tasks, SSTable counts, read/write latency, disk I/O) to identify symptoms:
High read latency & many SSTables? → Try Leveled.
Compaction backlog & disk space pressure? → Check thresholds, try Time-Window.
Write stalls during compaction? → Size thresholds may be too aggressive; consider Leveled or tune STCS thresholds.
This catalog provides the mental models and specific strategies to diagnose and configure compaction effectively for your workload.
No read-performance benefit from merging. Can lead to fragmentation if many small files expire.
Incremental / Delta Compaction
Maintain a small, constantly updated "delta" layer (e.g., in-memory or fast disk) for latest changes. Periodically merge this delta with the older, large immutable "base" layer.
Balancing Freshness & Read Cost.
Hybrid workloads with streaming ingestion and historical queries. Used by Delta Lake, Hudi (Copy-on-Write), and some data warehouses.
Complexity in query planning (must read from both layers). Delta layer can become a bottleneck.
Key-Based / Partition-Level Compaction
Trigger compaction per partition/keyspace when its SSTables exceed a threshold. Isolates compaction noise.
Multi-Tenancy & Noise Isolation.
SaaS applications with many tenants, where hot partitions need isolation from cold ones.
Complexity in management. Can lead to uneven storage usage.
Hybrid Strategies (e.g., Leveled Time-Window)
Apply different strategies based on data age or type. E.g., STCS for recent hours, LCS for "hot" partitions, TWCS for old data.
Tailored Optimization.
Systems with diverse access patterns (e.g., recent "hot" data + historical "cold" data).
High configuration complexity. Requires workload analysis.