Small Files in Data Lakes: How Parquet Can Become Your Bottleneck

Small Files in Data Lakes: How Parquet Can Become Your Bottleneck

Small files are one of those data lake problems that often go unnoticed until performance and operational costs start to hurt. This article explains why excessive small Parquet files are problematic, how they affect Spark, Athena, and S3 workloads, and what data engineers can do to prevent and fix them.

Mid-level Data Engineer | SQL | Python | AWS | ETL | Data Pipelines | IA

Small Files: The Silent Problem in Your Data Lake

One of the easiest ways to create a performance problem in a data lake is also one of the easiest to overlook:
creating too many small files.
Your data can be stored in Amazon S3, your tables can use Parquet, and your queries can still be slower and more expensive than they should be.
The problem is not necessarily the amount of data.
Sometimes, it is the number of files.

What is the small files problem?

There is no universal definition of a "small file". The problem starts when the number of files becomes disproportionate to the amount of data they contain.
For example:
1 TB
100 files × 10 GB
versus:
1 TB
1,000,000 files × ~1 MB
Both datasets contain approximately the same amount of data.
But they are very different from a processing perspective.
The second dataset requires the platform to deal with one million individual objects instead of one hundred.
That creates overhead during file discovery, planning, scheduling, and reading.

Why does this happen?

Small files are usually a consequence of pipeline design.
Common causes include:
  • Frequent micro-batch writes
  • Too many Spark output partitions
  • Excessive table partitioning
  • High-cardinality partition keys
  • Multiple jobs writing independently to the same dataset
  • Writing data before enough records have accumulated
For example, a pipeline that writes every few minutes may continuously produce:
part-00001.parquet
part-00002.parquet
part-00003.parquet
...
The individual files may be tiny, but after months of ingestion, the table can contain millions of them.

But I use Parquet. Isn't that supposed to be efficient?

Yes.
And that is exactly why small files are interesting.
Parquet is a column-oriented format designed for analytical workloads. It organizes data into row groups and column chunks and stores metadata that allows query engines to avoid reading unnecessary data.
For example:
Parquet
├── Row Group
│ ├── customer_id
│ ├── amount
│ └── created_at
│
├── Row Group
│ ├── customer_id
│ ├── amount
│ └── created_at
│
└── Metadata
This allows engines such as Athena and Spark to take advantage of column pruning, compression, predicate pushdown, and statistics.
But every Parquet file has its own metadata and structure.
If we create millions of tiny Parquet files, we repeatedly pay that overhead.
So Parquet does not eliminate the small files problem.
A good file format can still be used in a bad physical layout.

What happens to Spark and Athena?

With Spark, a large number of small input files can create many small tasks.
The cluster may spend significant time scheduling and coordinating work instead of processing meaningful amounts of data.
With Athena, a large number of files also increases the amount of metadata and file-level work involved in query execution.
This can lead to an important misconception:
"The query only scans a few gigabytes, so it should be fast."
Not necessarily.
Data volume is only one part of the problem. File count matters too.

How do we prevent it?

The best solution is to prevent fragmentation at the source.
Review:
  • How often the pipeline writes data
  • How many output partitions Spark creates
  • How your table is partitioned
  • Whether partition keys have high cardinality
  • How much data is written per batch
Don't blindly use:
df.coalesce(1)
just to reduce the number of files.
That can create a different bottleneck by eliminating parallelism.
The goal is not to create the fewest files possible.
The goal is to create a reasonable number of appropriately sized files.

What about files that already exist?

Then compaction becomes important.
A common architecture is:
Ingestion
↓
Small files
↓
Compaction
↓
Optimized Parquet
↓
Athena / Spark
AWS Glue can be used to compact datasets, and managed compaction is also available for Apache Iceberg tables.
The exact target file size depends on the workload, but values such as 256 MB, 512 MB, or larger are often reasonable starting points.
The important part is not the magic number.
Measure the workload and tune based on how the data is actually being queried.

The takeaway

Small files are not simply a storage problem.
They are a data layout problem.
When designing a data lake, don't only ask:
"How quickly can I ingest this data?"
Also ask:
"How will this data be read when the dataset is 100 times larger?"
Parquet, S3, Spark, Athena, and Glue are powerful technologies.
But they cannot compensate for a poorly designed physical data layout.
Optimize the files, not just the pipeline.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article