How We Slashed Athena Costs by Over 70% — And Made Queries Faster

How We Slashed Athena Costs by Over 70% — And Made Queries Faster

●1 ●2 ●5
calendar_today ago • schedule3 min read

Iceberg Is Not Set-and-Forget: The Hidden Cost of Neglecting Table Maintenance

A story about what really happens when you treat Iceberg as “set it and forget it.”

Most performance issues don’t arrive suddenly. They creep in quietly — one streaming batch, one CDC update, one snapshot at a time.

Then one morning you open your dashboard and realise your once-fast tables have become sluggish, bloated and dangerously expensive.

That was the moment we knew something was wrong.

For months, our Iceberg tables had been absorbing millions of incremental writes. Everything looked fine on the surface — until it wasn’t.

Queries slowed down. Storage ballooned. Athena costs spiked. Jobs began failing for reasons that seemed completely random.

But none of this was random.

This was the natural consequence of a truth most teams eventually learn:

Iceberg is powerful, but it does not clean up after you.

If you don’t actively maintain your tables, you’re quietly building a time bomb.

The Symptoms: What Neglected Iceberg Tables Look Like

As our data scaled, the cracks became impossible to ignore.

🔹 Athena Costs Exploded

Our daily scans hit 22 TB/day — at $5 per TB.

Partition pruning wasn’t happening. Old files were still in S3. Orphaned files accumulated silently.

🔹 Queries Became Painfully Slow

Simple queries took up to 3 minutes, scanning massive portions of the dataset.

query-performance

🔹 Commit Exceptions Everywhere

Long metadata chains meant longer planning times, which caused retries — sometimes cascading failures.

🔹 Maintenance Jobs Fell Behind

Compactions and rewrite tasks simply couldn’t catch up with the rate of table bloat.

The tables were screaming at us — we just weren’t listening.

The Root Causes: What Was Actually Happening

When we dug into the internals, the source of the problem became obvious.

Over time, our tables had accumulated four forms of Iceberg debt:

1. Small Parquet Files Everywhere

Instead of a few 128–512 MB files, we had hundreds of 5–10 MB fragments.

Athena hates this — each read brings overhead, latency and higher scan costs.

2. Growing Delete Files

Deleted rows were logically removed but still physically stored, multiplying scan work.

3. Long Snapshot Metadata Chains

Hundreds of snapshots meant slow planning and a high chance of commit exceptions.

4. Orphaned Data Files

Unreferenced files still lived in S3, quietly increasing our bills.

Left untouched, these issues compound — and performance falls off a cliff.

The Turning Point: Designing a Full Optimization Strategy

We realised quickly that a one-off cleanup wasn’t enough.

The tables needed a structured, ongoing maintenance strategy — one that addressed both the symptoms and the causes.

We broke the solution into three pillars:

✔ Table Optimization: Fix the Foundation

We began by tuning Iceberg table properties to reduce planning overhead and improve pruning accuracy.

✔ Smarter Data Organisation with Z-Order Sorting

Most of our analytical queries filtered on a combination of dominant columns.

Z-order sorting compressed related values close together, making predicate pushdown dramatically more effective and allowing Athena to skip huge chunks of data.

This had one of the biggest impacts on scanned data reduction.

✔ Reshaping File Layout (Rewrite & Compaction)

We ran a disciplined sequence of operations:

  • Optimise / Rewrite Data Files

    Merged tiny files into healthy, large Parquet files.

  • Rewrite Sorted Data Files (Rolling Windows)

    We couldn’t rewrite the entire table at once — too expensive.

    Instead, we used rolling windows to gradually re-sort and rewrite portions of the dataset.

  • Rewrite Positional Deletes

    This prevented new unreferenced files from ballooning the table size.

  • Vacuum

    Cleaned old snapshots, trimmed metadata and removed orphaned files.

These changes alone transformed query performance.

query-improvements

The Results: What Actually Changed

Once we implemented the full optimisation strategy, the transformation was immediate.

Queries that previously took minutes now completed in a few seconds.

Scan volumes dropped dramatically as Athena stopped reading unnecessary data and our S3 footprint shrank as we eliminated small files, deletes and orphaned artifacts.

Metadata became lighter, planning became faster and commit exceptions nearly disappeared.

Overall, the platform became faster, cheaper and far more stable.

What had once felt like a growing operational burden turned into a well-tuned, predictable system — proof that consistent Iceberg maintenance pays off at scale.

Final Thoughts: The Real Lesson

Iceberg delivers huge value — scalability, schema evolution, ACID transactions and time travel. But none of that matters if you treat it as a fire-and-forget system.

The truth is simple:

Iceberg is a living system.

If you don’t maintain it, performance will decay.

If you do, the results speak for themselves.

For us, those results were lower costs, faster queries and a far more resilient platform.

And more importantly — we now treat optimisation as part of the job, not an afterthought.

Want more #software-engineering & #dataengineering deep dives?

Join 6,051+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

More Posts

Local-First: The Browser as the Vault

Pocket Portfolio - Apr 20

Make for Small Business: What It Is, What It Costs, and When to Use It

floxolab - Oct 23

The Esoteric Realms of Code

nevmenandr - Nov 14

SEO Rates Philippines 2026: Costs & Packages | FloxoLab

floxolab - Oct 18

The Languages of Machines and Humans: A Developer's Perspective

nevmenandr - Nov 4
chevron_left
233 Points • 8 Badges
6Posts
0Comments
1Connections
Senior Backend / Full Stack Software Engineer specializing in distributed systems, cloud infrastruct... Show more

Related Jobs

View all jobs →

Commenters (This Week)

1 comment
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!