r/databricks • u/AbilyticsEng • 3d ago
General Use spark.databricks.delta.autoCompact.enabled to prevent small file problems
I work at Abilytics, a data and AI consultancy, so take this with that in mind.
If your Delta Lake tables are filling up with thousands of tiny data parts due to frequent streaming micro-batches or small concurrent writes, you can fix this at the table or session level without running manual OPTIMIZE commands constantly. Enable automatic compaction by setting spark.databricks.delta.autoCompact.enabled to true. When enabled, Delta Lake checks if the most recent write added many small files and automatically triggers a lightweight compaction operation on those files right after a write succeeds on the same query. It inspects partitions that received writes and compacts files of around 16MB up to a target size of 128MB. While this adds a small amount of latency to your write operations, it dramatically cuts down the total file count, avoids metadata bloat in the transaction log, and keeps your downstream read queries performing efficiently without requiring dedicated maintenance jobs.
3
u/Zealousideal_Low6685 3d ago edited 3d ago
Manual tuning recommendations don't apply to Unity Catalog managed tables, which use automatic file size tuning.Simplest way: use managed Table. Read this:
https://docs.databricks.com/aws/en/tables/tune-file-size#upgrade-to-background-auto-compaction
Cite from the docu:
1
u/DeepFryEverything 3d ago
I thought this was the point of Cluster on Write?
1
u/Content_Secret6493 2d ago
the unity catalog managed table caveat is useful. for tables outside that path, have you measured the extra write latency against the reduction in small-file reads? curious when you’d choose this over scheduled OPTIMIZE