Apache Spark Big Data (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
File Compaction Strategies: Small file problem mitigation in Delta Lake/Iceberg.
senior LevelCode Exampleapache-sparkAdvanced Internals
In Simple Words: Streaming or hourly ingestion creates millions of tiny 1MB files. Query engines spend 90% of their time on object storage HTTP listing and opening file headers:
- The Solution: Periodic file compaction:
sql
-- Delta Lake OPTIMIZE sales_table ZORDER BY (customer_id); -- Apache Iceberg CALL system.rewrite_data_files('sales_table'); - Rewrites millions of fragmented tiny files into optimal 128 MB to 512 MB Parquet files, accelerating subsequent queries by up to 10x.