liveBook · Manning

Compaction

As explained in Architecting an Apache Iceberg Lakehouse

A compaction strategy defines how fragmented data and delete files are consolidated based on factors such as activity, size, or freshness.

Compaction reorganizes fragmented Iceberg data and metadata by rewriting files and manifests. It consolidates small files, applies delete files, improves data colocation, and restores more predictable planning and query performance. section 10.2 section 10.2.1

Frequent micro-batch or streaming commits improve freshness but create file fragmentation and metadata growth. Compaction balances that ingestion benefit against read efficiency, compute use, concurrent-workload impact, and maintenance cost. section 6.1.1 section 6.2.3

A practical compaction strategy makes several implementation decisions:

  • Choose bin-pack to combine files toward a target size, or sort compaction to reorder records for better locality and filtered-query pruning. section 10.2.1
  • Select eligible files with size and count thresholds, then group them into independently processed file sets for parallelism and controlled resource use. section 10.2.3
  • Scope rewrites by partition, time window, or business predicate to prioritize hot or degraded areas and keep jobs within operational limits. section 10.2.4
  • Align sorting, partition evolution, and file layout with query access patterns rather than applying one physical organization uniformly. section 10.1.2 section 10.2.4
  • Treat merge-on-read maintenance as essential: applying accumulated delete files during rewrites reduces read-time reconciliation overhead, while copy-on-write shifts cost toward writes. section 10.1.4 section 10.5
  • Automate threshold-driven jobs with metadata-aware orchestration, and coordinate compaction with snapshot expiration and orphan-file cleanup. section 11.1 section 11.1.1

Scoped rewrite for a hot partition

A Spark maintenance workflow can rewrite only files matching region = 'us-west', or combine that predicate with a sale_date range. A metadata check can trigger the job when small-file or delete-file thresholds are breached, leaving other partitions untouched. section 10.2.4 section 11.1.1

Figure 10.7 During compaction, data files are written into fewer, larger files, and manifests are rewritten so that fewer manifests track more files. This improves table performance that has degraded after many writes.

Shows how compaction produces fewer, larger data files and rewrites manifests so metadata tracks the table more efficiently. section 10.2

How Architecting an Apache Iceberg Lakehouse covers it

How deep it goes
Explains rewriting, bin-pack and sort strategies, file selection, filters, target sizing, and orchestration while deferring detailed specification semantics.
Examples
Uses Spark and Dremio rewrite procedures, bin-pack and sort commands, target file sizes, and region- and date-filtered maintenance jobs.
What it assumes
Assumes familiarity with Iceberg tables, data files, manifests, partitions, and ingestion while introducing compaction’s maintenance purpose and configuration choices.
What you can do after
Operate/configure it through Spark, Dremio, or orchestration tools using thresholds, target sizes, sort strategies, predicates, and metadata-based triggers.
How it connects
Connects compaction to micro-batching, streaming ingestion, metadata management, partition evolution, sort orders, merge-on-read, copy-on-write, and workflow orchestration.

Also explained in

Compare how 5 books explain compaction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Architecting an Apache Iceberg Lakehouse. The section links point to the parts of the book it draws on.