Small files problem
| Also known as | Small file problem; file fragmentation |
|---|---|
| Field | Data storage, table maintenance |
| Key parts | Target file size, compaction, write-time file sizing, clustering |
| Open source implementations | Apache Iceberg, Delta Lake, Apache Hudi, Apache Spark |
| Related | Copy-on-write and merge-on-read, Deletion vector, Partition, Structured Streaming |
The small files problem is the slowdown and extra cost that occur when a table's data is spread across many files that are much smaller than the size the storage and query engines work best with. Every file adds metadata to track, a request to open it, and planning and scheduling work, so a table with many small files is slower to query and maintain than the same data in fewer, larger files.[1][2] In an open lakehouse, small files come mostly from frequent small writes, and every major open table format provides compaction and write-time sizing to control them.
Causes
Streaming and micro-batch writes. Each batch commits its own files. The Iceberg documentation notes that the amount of data written by a streaming process is typically small, which makes the table metadata track many small files.[3] Hudi's clustering documentation describes the same tension: ingestion prefers small files for parallelism and freshness, while queries degrade with many small files.[4]
Many partitions per write task. A file cannot span a table partition, and in Spark a file cannot be larger than the task that writes it. When one Spark task writes to several Iceberg partitions, each partition gets its own, smaller file.[5] High-cardinality partitioning multiplies the number of files per commit.
Compression and columnar encoding. The size on disk is much smaller than the in-memory size of the task's rows, because the data is compressed and columnar. The Iceberg documentation gives the example that a 100 MB Spark task produces a file much smaller than 100 MB.[5]
Row-level changes. Merge-on-read writes add small delete files. Iceberg's maintenance guide recommends compacting small position delete files because of the metadata and file-open overhead they add.[6]
Costs
- Metadata. Iceberg tracks every data file in manifests, so more files means more metadata, and small files cause an unnecessary amount of it.[2]
- File open and request cost. Hudi's documentation points out that object stores such as S3 rate-limit requests per prefix, and that each file needs at least one request regardless of size, plus fixed costs to open and close it.[1] Spark models this fixed cost with
spark.sql.files.openCostInBytes(default 4 MB) when packing files into read partitions.[7] - Planning and scheduling. More files mean more tasks, which adds scheduling overhead and memory pressure to Spark, Flink or Hive jobs.[1]
- Storage efficiency. Many small files can compress less well and need more index and statistics metadata.[1]
Remedies by project
Apache Iceberg
Iceberg writers roll over to a new file when it reaches write.target-file-size-bytes, default 536870912 bytes (512 MB); delete files have a separate target, write.delete.target-file-size-bytes, default 64 MB.[8] Because a Spark task may be too small to reach the target, the Iceberg documentation advises controlling what data each task receives with write.distribution-mode or an explicit repartition.[5]
For existing files, the rewrite_data_files procedure compacts small files into larger ones, using bin-packing by default or a sort. Its options include target-file-size-bytes (defaulting to the table's target), min-file-size-bytes (75% of the target), max-file-size-bytes (180% of the target) and min-input-files (5).[2] The rewrite_manifests procedure addresses the matching problem in metadata, since fast appends in streaming workloads can leave many small manifest files.[3]
-- Apache Iceberg (Spark SQL): compact one day's files toward 512 MB
CALL catalog.system.rewrite_data_files(
table => 'db.events',
where => 'event_date = "2026-11-21"',
options => map('target-file-size-bytes', '536870912')
);
Delta Lake
Delta Lake's OPTIMIZE command (from 1.2.0) coalesces small files into larger ones by bin-packing and can be limited to a partition predicate with WHERE.[9]
Auto compaction (from 3.1.0) runs synchronously after a successful write and compacts small files in the affected partitions. It is enabled with the table property delta.autoOptimize.autoCompact or the session setting spark.databricks.delta.autoCompact.enabled, uses a 128 MB target by default, and is tuned with spark.databricks.delta.autoCompact.maxFileSize and spark.databricks.delta.autoCompact.minNumFiles.[9]
Optimized writes (from 3.1.0) shuffle data before writing so that each partition receives fewer, larger files, at the cost of extra write latency. The feature is off by default and is enabled with the table property delta.autoOptimize.optimizeWrite, the setting spark.databricks.delta.optimizeWrite.enabled, or the writer option optimizeWrite; spark.databricks.delta.optimizeWrite.binSize (default 512 MiB) sets the target in-memory size of each output file.[9]
Apache Hudi
Hudi sizes files during writes. On insert and upsert, it adds records to existing files smaller than hoodie.parquet.small.file.limit (default 104857600 bytes, 100 MB) until they approach hoodie.parquet.max.file.size (default 125829120 bytes, 120 MB). The bulk_insert operation does not size files this way.[1] For merge-on-read tables, hoodie.merge.small.file.group.candidates.limit (default 1) limits how many small file groups an upsert may expand, to limit rewriting.[1]
After writes, Hudi's clustering table service stitches small files into larger ones and can sort data for locality. It runs inline after each write when hoodie.clustering.inline is true, or asynchronously with hoodie.clustering.async.enabled; both default to false.[4][10] Files under hoodie.clustering.plan.strategy.small.file.limit (default 314572800 bytes) are candidates.[10]
Apache Spark
Spark settings shape how many files a write produces, independent of the table format.
spark.sql.files.maxRecordsPerFilecaps the rows in one output file; the default 0 means no limit.[7]- The
COALESCE,REPARTITION,REBALANCEandREBALANCE_BY_SIZESQL hints, and the matchingcoalesceandrepartitionDataset methods, control the number of output files.REBALANCEasks adaptive query execution (AQE) for output partitions of reasonable size, to avoid files that are too small or too big, and is ignored when AQE is disabled.[11] - With AQE (
spark.sql.adaptive.enabled, default true),spark.sql.adaptive.coalescePartitions.enabled(default true) merges small shuffle partitions towardspark.sql.adaptive.advisoryPartitionSizeInBytes.[12][7] The Iceberg documentation notes that this advisory size measures shuffle data, not the compressed columnar file, so it must be set larger than the desired file size.[5] - On the read side,
spark.sql.files.maxPartitionBytes(default 128 MB) andspark.sql.files.openCostInBytescontrol how many small files are packed into one read partition.[7]
See also
- Copy-on-write and merge-on-read
- Deletion vector
- Structured Streaming
- Partition
- Shuffle
- Open table format
References
- ↑ 1.0 1.1 1.2 1.3 1.4 1.5 File Sizing (version 1.2.1). Apache Hudi.Retrieved 2026-11-22.
- ↑ 2.0 2.1 2.2 Spark Procedures. Apache Iceberg.Retrieved 2026-11-22.
- ↑ 3.0 3.1 Spark Structured Streaming. Apache Iceberg.Retrieved 2026-11-22.
- ↑ 4.0 4.1 Clustering (version 1.2.1). Apache Hudi.Retrieved 2026-11-22.
- ↑ 5.0 5.1 5.2 5.3 Spark Writes. Apache Iceberg.Retrieved 2026-11-22.
- ↑ Maintenance. Apache Iceberg.Retrieved 2026-11-22.
- ↑ 7.0 7.1 7.2 7.3 SQLConf.scala (Apache Spark v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
- ↑ Configuration. Apache Iceberg.Retrieved 2026-11-22.
- ↑ 9.0 9.1 9.2 Optimizations. Delta Lake.Retrieved 2026-11-22.
- ↑ 10.0 10.1 All Configurations. Apache Hudi.Retrieved 2026-11-22.
- ↑ Hints (Spark 4.3.0 documentation). Apache Software Foundation.Retrieved 2026-11-22.
- ↑ Performance Tuning (Spark 4.3.0 documentation). Apache Software Foundation.Retrieved 2026-11-22.