Lake Architecture on S3
Lake Architecture on S3
Treat S3 as the single source of truth and separate zones: raw/ holds immutable landing files exactly as produced; curated/ holds cleansed, typed, partitioned data ready for analysis. Convert to a columnar format — Parquet or ORC — organized Hive-style:
s3://lake/orders/dt=2026-09-01/part-00042.parquet
Partition directories let Athena prune files before scanning, and columnar files let it read three columns out of fifty. Schema lives in the Glue Data Catalog rather than in code, so Athena, Redshift Spectrum, and EMR share one definition. Storage is cheap and elastic; compute is only billed while a query runs — the lake model decouples the two.
Cataloging and Querying with Glue and Athena
Cataloging and Querying with Glue and Athena
A Glue crawler walks a prefix, infers schema, and writes a table (plus partitions) into the Data Catalog. Then query in place:
CREATE TABLE orders_parquet
WITH (format = 'PARQUET', parquet_compression = 'SNAPPY') AS
SELECT order_id, customer_id, total
FROM orders_raw
WHERE dt >= '2026-01-01';
CTAS migrates JSON to Parquet while you query. For fast-growing partitions, use partition projection — Athena computes partition paths from a pattern instead of listing the catalog — and organize work in workgroups so teams share settings, results, and spend limits without colliding.
Pitfalls and Cost Control
Pitfalls and Cost Control
Athena bills per byte scanned, so every design choice below cuts cost:
- One file per writer creates thousands of tiny objects — slow to list and slow to read. Compact into larger files during ETL.
- Over-partitioning (
hour=,user=) multiplies listings; partition on high-selectivity filters only. SELECT *from JSON scans everything; select explicit columns from Parquet.- Catalog drift: files changed under a crawler-defined table return wrong results — re-crawl after loads.
- Keep Athena and the data in the same region to avoid needless transfer.
Other traps: malformed CSV SerDe settings silently null columns, and ungoverned lifecycle rules archive data your nightly job still reads.
Quiz
1. Why does a partitioned prefix like orders/dt=... reduce Athena cost?
2. What does a Glue crawler actually produce?
3. Your query got slower after a big backfill. Most likely cause?
Flashcards
Question
Hive-style layout
Click to reveal answer
Answer
key=value/ subdirectories (dt=2026-09-01/) that enable partition pruning.
Question
Glue Data Catalog
Click to reveal answer
Answer
Hive-compatible metadata store that Athena, Spectrum, and EMR share.
Question
Athena pricing driver
Click to reveal answer
Answer
Billed per byte scanned — columnar format + column selection + partitions = cost control.
Question
Partition projection
Click to reveal answer
Answer
Athena derives partition paths from a pattern, avoiding crawler calls for new partitions.
Question
Small files problem
Click to reveal answer
Answer
One file per writer → thousands of tiny objects; compact them during ETL.
Revision Notes
Key Takeaways
- 1. S3 zones + Parquet + Hive layout are the lake foundation
- 2. Glue catalogs schema; Athena queries in place with no cluster to manage
- 3. Cost tracks bytes scanned — prune, project, and select columns deliberately
Interview Tips
- • When asked to cut Athena cost, name three levers: format, column selection, partition pruning
- • Explain raw vs curated zones and who is allowed to write to each
Cheat Sheet
Lake: raw/ + curated/, Parquet + dt= partitions. Glue crawler → catalog; Athena scans per byte. Prune partitions, SELECT columns, compact small files, partition projection, same region.
Continue Learning
Before You Start
- No prerequisites listed.