
Iceberg Compaction Strategies: A Practical Guide
A deep guide to bin-pack, sort, and Z-order compaction strategies for Apache Iceberg — when to use each, how to configure them, and how to automate strategy selection across hundreds of tables.
Intelligent Compaction
Merges small files and sorts them by the columns your queries filter on, when each table needs it. Runs on a Rust engine, 95% faster than Spark, with no jobs to schedule.
LakeOps| Operation | Table | Duration | Impact | Time | Status |
|---|---|---|---|---|---|
| Compact Data Files | customer_orders orders | 4s | 1.24 TB, 16 → 1 files | 57 minutes ago | SUCCESS |
| Expire Snapshots | payment_transactions payments | 27s | 8.2 TB | 4 hours ago | SUCCESS |
| Expire Snapshots | inventory_snapshots_20250702 warehouse | 3s | 2.1 TB | 4 hours ago | SUCCESS |
| Rewrite Manifests | raw_clickstream analytics | 1.9s | 3 → 1 manifests | 5 hours ago | SUCCESS |
| Compact Data Files | product_catalog products | 6m 11.3s | 3,008 → 1,256 files | 6 hours ago | SUCCESS |
Open and runs on your stack
How it works
LakeOps measures every table's files from its metadata, compacts the tables that need it, and records every run.
Point LakeOps at AWS Glue or any Iceberg REST catalog. Your data stays in your bucket.
Each scan tracks small files, compactable bytes, and delete files in every table.
Bin-pack or sort on the Rust engine, committed as a new snapshot. Writers keep going.
Every run is logged in Events with files in and out, duration, and status.
Monitoring started at seq #4,812. Everything written from that point on is in scope.
01 · When to compact
Access patterns · 2,847 queries
customer_idevent_dateproduct_idregionBefore
After
Query time
12×
faster, 51% less scanned
Compute cost
−76%
query CPU
Storage cost
−62%
S3 GET requests
02 · Query-aware sort
Binpack compaction · 200 GB / 600M rows
Production tables · files
balance_snapshots1,192 GB11,957→3,270raw_sdk_events8 GB42,633→69cluster_registry322 GB878→40095%
Faster than Spark
90%
Cheaper than Spark
2,522
Peak MB/s
0
Clusters to run
03 · Rust engine
Strategy
Binpack
Merge small files to the target size
Sort
Cluster rows so engines skip files
Target file size
512 MB
Sort order
customer_id, event_date
Predicate
file_size < 134217728 OR delete_file_count > 0Scope
Binpack
Default strategy
Sort
With a sort order
512 MB
Default target
04 · Bin-pack or sort
Before
After
05 · Delete files
Sort by event_date, regionsim/sort-date-region
Sort by customer_id, event_dateBest matchsim/sort-cust-date
Sort by product_id, regionsim/sort-prod-region
76%
Less data scanned
12.4×
Estimated speedup
0
Production writes
06 · Layout simulations
Manage maintenance, configuration, and lifecycle policies for your data lakehouse
| On | Policy | Type | Next Run | Last Run | Updated | Actions |
|---|---|---|---|---|---|---|
orders_critical | Compact Files | Apr 25, 2026, 8:12 AM | Apr 25, 2026, 03:05 AM | Feb 01, 2025, 3:46 PM | ••• | |
payments_compact | Compact Files | Feb 15, 2026, 12:06 AM | Feb 1, 2025, 02:18 PM | Feb 5, 2025, 4:03 PM | ••• | |
Remove orphan files (e-ip...) For all tables in all catalogs every 7 days | Orphan Files | Apr 25, 2026, 8:12 AM | Apr 25, 2026, 04:07 PM | Jun 23, 2025, 04:01 PM | ••• | |
clickstream_cdc_events_p | Expire Snapshots | Apr 25, 2026, 12:03 AM | Apr 25, 2026, 03:05 AM | Jan 28, 2025, 03:25 PM | ••• | |
sessions_cdc_events_p | Expire Snapshots | Apr 25, 2026, 12:03 AM | Apr 26, 2026, 03:05 AM | Jun 26, 2025, 11:11 PM | ••• | |
global_expire_snapshots Runs snapshot expiration on all tables once a day | Expire Snapshots | Apr 26, 2026, 1:18 PM | Apr 07, 2026, 01:08 PM | Mar 14, 2026, 8:42 AM | ••• | |
manifest_rewrite_weekly Rewrite manifests for all critical tables weekly | Rewrite Manifests | Apr 28, 2026, 2:00 AM | Apr 21, 2026, 02:00 AM | Mar 10, 2026, 9:15 AM | ••• | |
staging_config | Configuration | — | — | Dec 31, 2025, 02:45 PM | ••• |
07 · Policies
View and track table operations and history
| Table Name | Namespace | Catalog | Operation Type | Impact | Duration | Start Time | Status |
|---|---|---|---|---|---|---|---|
| customer_orders | orders | ecommerce_prod | Compact Data Files | 1.24 TB, 16 → 1 files | 4s | 57 min ago | SUCCESS |
| customer_orders | orders | ecommerce_prod | Compact Data Files | 11 → 8 files | 10.3s | 2h ago | SUCCESS |
| customer_orders | orders | ecommerce_prod | Compact Data Files | 970 → 87 files | 6m 1.0s | 3h ago | SUCCESS |
| payment_transactions | payments | ecommerce_prod | Expire Snapshots | 1 snapshot | 4.6s | 4h ago | SUCCESS |
| payment_transactions | payments | ecommerce_prod | Rewrite Manifests | 3 → 1 manifests | 1.9s | 4h ago | SUCCESS |
| raw_clickstream | analytics | marketing_events | Compact Data Files | 970 → 87 files | 9m 31.6s | 5h ago | SUCCESS |
| user_sessions | analytics | marketing_events | Remove Orphan Files | 1,203 files, 847 MB | 1m 12s | 5h ago | SUCCESS |
| product_catalog | products | ecommerce_prod | Compact Data Files | 3,008 → 1,256 files | 6m 11.3s | 6h ago | SUCCESS |
| user_sessions | analytics | marketing_events | Rewrite Manifests | 2 → 1 manifests | 1.8s | 7h ago | SUCCESS |
| inventory_levels | operations | warehouse_analytics | Remove Orphan Files | 4,218 files, 1.9 GB | 3m 44s | 7h ago | SUCCESS |
| inventory_levels | operations | warehouse_analytics | Expire Snapshots | 12 snapshots expired | 2.0s | 8h ago | SUCCESS |
| shipping_events | logistics | warehouse_analytics | Rewrite Manifests | 3 → 1 manifests | 1.0s | 8h ago | SUCCESS |
08 · Every run on record
LakeOps reads your Iceberg metadata. Data stays in your storage.
Every table's health and what it needs, from the first scan.
Autopilot, on-demand runs, or your own policies.
The challenge
Every engine that reads a fragmented table pays for it on every query: more files to open, more data to scan, more storage requests.
A stream that commits every 30 seconds makes 2,880 commits a day, each writing files far below the 128–512 MB that engines read best.
Nightly jobs rewrite tables that were already healthy and leave busy ones fragmented until the next run.
Compaction is read, merge, write. Spark adds clusters to size, JVMs to tune, and out-of-memory failures on terabyte tables.
Bin-packing fixes the file count, but unsorted rows give every file wide min/max ranges, so engines still read most of them.
Compare
Managed optimizers work inside one platform, and Spark jobs work until the lake grows. LakeOps compacts across your catalogs, in place, on a faster engine.
| Capability | Spark rewrite_data_files + cron | AWS Glue compaction optimizer | Amazon S3 Tables | LakeOps |
|---|---|---|---|---|
| Where it works | Any catalog, if you write and run the jobs | Tables in the AWS Glue Data Catalog | Tables in S3 table buckets | AWS Glue, S3 Tables, and any Iceberg REST catalog (Polaris, Nessie, and more), in place |
| When it runs | On the schedule you set, whether or not a table needs it | Automatically, per table, once enabled | Automatically, managed by S3 | When each table's file signals say it's due, or inside your cron window |
| How files are laid out | Binpack, sort, or z-order on columns you choose | Binpack, sort, or z-order on the table's sort order | Binpack, sort, or z-order on the table's sort order | Binpack, or sort by the columns your queries filter, join, and group on |
| Engine | Your Spark clusters: 1,612s for 200 GB | AWS-managed, billed in DPU-hours | AWS-managed: 6,300s for 200 GB | Rust on Apache DataFusion: 221s for 200 GB |
| Cost to compact | Spark cluster compute, plus idle cluster time | Per DPU-hour of each run | Per object and per GB processed | About 90% less compute than Spark, with no cluster to run |
| Visibility | Logs and dashboards you build | Run history per optimizer | Maintenance status per table | The signals behind each run, and files in and out for every run in Events |
Benchmark: binpack compaction of a 200 GB, 600M-row Parquet table with the same target file size. AWS Glue and Amazon S3 Tables details are from public AWS documentation, November 2026.
Results
Benchmarks from production-grade tables across multiple engines and clouds.
Query speed
After compaction + layout optimization
CPU reduction
Compute hours across all engines
Storage saved
Orphans, snapshots & bloat removed
Table health
Autonomous maintenance keeps every table optimized
See it in action
Compaction and the rest of table maintenance, run when each table needs it.
FAQ
Streaming and frequent small commits leave tables with thousands of small files. Every file adds a storage request, metadata to plan over, and work for the engine, so queries slow down and cost more. Compaction merges small files into files near the target size, so engines open fewer files and read less data.
When a meaningful share of its files are well below the target size, or delete files are piling up. LakeOps measures the share of small files, compactable bytes, and delete files on every scan. In Automatic mode it compacts when those signals cross a threshold; in Scheduled mode it compacts inside your cron window, only when it's due.
Bin-pack merges small files to the target size without reordering rows. It's the fastest fix for small-file pressure and the default. Sort rewrites files in the table's sort order, so engines skip more files on filtered queries. Use it on large, read-heavy tables. When a run doesn't specify a strategy, LakeOps sorts if the table has a sort order and bin-packs otherwise. The default target is the table's write.target-file-size-bytes, or 512 MB.
Query-aware compaction looks at which columns your queries filter, join, and group on, then sorts data files to match. Rows with nearby values land in the same files, so column statistics are tight and engines skip whole files instead of scanning them.
LakeOps runs compaction on a purpose-built Rust engine on Apache DataFusion instead of Spark: no cluster to size, no JVM to tune. In a 200 GB benchmark it finished in 221 seconds versus 1,612 for Spark, about 95% faster and 90% cheaper. LakeOps also decides when each table needs compacting, so there's no job to schedule.
No. LakeOps writes the new files to your bucket and commits them as a new Iceberg snapshot. Readers see either the old files or the new ones, never a mix, and writers keep committing.
No. LakeOps reads Iceberg metadata from your catalog, reads only the files it rewrites, writes the compacted files to your own bucket, and commits through your catalog. Your data never leaves your storage.
Related
Resources
No Spark jobs to write. See which tables need compaction, and what it saves.