Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. Athena and query-on-lake engines

Cloud · AWS & Azure

Athena and query-on-lake engines

Easycloud-35
awsathenacost-optimizations3sql

Question

What is Amazon Athena, and how do you keep its costs low?

Solution

Amazon Athena is an interactive, serverless query service powered by Trino that executes SQL directly against files in Amazon S3 using metadata from the AWS Glue Data Catalog. Athena charges five dollars per terabyte of data scanned from storage, making query cost directly proportional to the physical bytes read from disk. Teams keep costs low by converting files to compressed columnar formats, establishing granular partitioning, enforcing query projection, and setting workgroup scan limits.

Billing model and storage formats

Because Athena does not bill for idle compute hours, storage layout directly dictates both query performance and monthly expenses.

Raw CSV Scan (Unpartitioned, 100 GB)  ---> 100 GB Scanned ($0.50)
Parquet Scan (Partitioned, Columns)   --->   2 GB Scanned ($0.01)

Applying foundational lake storage patterns yields massive cost reductions:

  • Convert uncompressed text formats like CSV and JSON into columnar Parquet or ORC. Columnar formats allow Athena to read only the specific columns requested in the query.
  • Always avoid select star queries. In a hundred-column table, reading only three required columns reduces scanned data volume by more than ninety percent.
  • Apply compression codecs such as Snappy or ZSTD. Compressed blocks occupy less physical space on S3, reducing scanned gigabytes immediately.
  • Structure data into partitions by date or geographic region so queries with where clauses read only matching S3 subdirectories.
  • Enable partition projection on high-cardinality partitioned datasets to avoid slow and expensive Glue Data Catalog partition list API calls.

Governance and modern table formats

Enterprise data environments implement structural guardrails to prevent rogue analytical queries from exhausting budgets:

  • Configure Athena workgroups with per-query and per-hour data scan caps. If an analyst submits an unpartitioned cross-join that exceeds the configured scan threshold, Athena cancels the query automatically.
  • Use Apache Iceberg tables within Athena. Iceberg maintains hierarchical file-level metadata and column min-max statistics, enabling the query engine to prune entire data files before scanning bytes from S3.
PreviousNext