Skip to content
AWSData LakePySparkData Engineering

Building a Medallion Data Lake on AWS: Bronze, Silver and Gold Layers with S3, Glue and Athena

Build a medallion data lake on AWS with S3, Glue and Athena: bronze, silver and gold layers, Parquet, partition projection, PySpark jobs and cost controls.

By 7 min read

A data lake that is just a bucket of files quickly turns into a data swamp: nobody knows which copy is correct, schemas drift and queries get slower every month. The medallion architecture fixes this by organizing data into three layers of increasing quality. This guide shows how to build one on AWS with Amazon S3, AWS Glue and Amazon Athena.

Why a layered data lake

The medallion pattern splits the lake into layers, each with a clear contract:

  • Bronze: raw data exactly as it arrived, append-only, kept for replay and audit.
  • Silver: cleaned, typed and deduplicated data with an enforced schema, the reliable source for engineers and data scientists.
  • Gold: business-ready tables modeled for reporting, such as facts, dimensions and aggregates.

Separating the layers means a bug in a transformation never destroys raw data. You fix the code and rebuild silver and gold from bronze.

On AWS, the end-to-end flow typically looks like this:

  • Database changes arrive through AWS DMS, and files or events arrive through batch uploads or Amazon Data Firehose, all landing in the bronze bucket.
  • Glue PySpark jobs read bronze, clean and deduplicate it, and write Parquet to the silver bucket.
  • Glue jobs, Athena CTAS queries or dbt models build gold tables from silver.
  • The Glue Data Catalog registers every table, Lake Formation controls access, and Athena, QuickSight or Redshift Spectrum query the results.
  • An orchestrator such as Step Functions or Amazon MWAA (managed Airflow) runs the jobs in order.

S3 layout, naming and file formats

Buckets and prefixes

Use one bucket per layer, such as myorg-lake-prod-bronze, myorg-lake-prod-silver and myorg-lake-prod-gold. Separate buckets make it simple to apply different lifecycle rules, encryption keys and access policies to each layer. Inside each bucket, keep paths predictable:

  • Follow <source or domain>/<table>/<partition>=<value>/ for every table.
  • Use lowercase snake_case for table and column names.
  • Use Hive-style partition folders such as ingest_date=2026-09-13, which Athena and Spark understand natively.

File formats and compression

Keep bronze in whatever format the source produces, whether JSON, CSV or Parquet from DMS, so the original is always available. From silver onward, use Apache Parquet, a columnar format that lets Athena read only the columns a query needs. Snappy compression is the common default; ZSTD compresses further at a slightly higher CPU cost.

Aim for files of roughly 128 MB to 1 GB, because thousands of tiny files slow down every query. For silver and gold tables that need updates and deletes, consider Apache Iceberg, an open table format supported by both Athena and Glue that adds MERGE, time travel and schema evolution on top of Parquet.

Bronze: landing raw and CDC data

Bronze should be boring: land data quickly, never modify it, and record when it arrived. Partitioning bronze by ingestion date makes it simple to reprocess one specific load.

For operational databases, AWS Database Migration Service (DMS) handles change data capture (CDC), which means streaming every insert, update and delete from the source database's transaction log. A typical setup runs a full load followed by ongoing replication into S3 as Parquet. Each change record carries an operation flag (I, U or D) and can include a commit timestamp, which silver jobs use to apply changes in order. The source must have its change log enabled, such as binary logging on MySQL or logical replication on PostgreSQL.

Silver: cleaning and cataloging data

The bronze-to-silver job enforces a schema, removes duplicates and standardizes values. The example below processes one ingestion date, keeps the latest version of each order and overwrites only that date's partition, so re-running it is safe.

import sys
from pyspark.sql import SparkSession, Window, functions as F

ingest_date = sys.argv[1]  # e.g. "2026-09-13"; on Glue, read it with getResolvedOptions
spark = (SparkSession.builder.appName("orders_bronze_to_silver")
         .config("spark.sql.sources.partitionOverwriteMode", "dynamic")
         .getOrCreate())

# Schema enforcement: declare types instead of letting Spark infer them
schema = ("order_id STRING, customer_id STRING, amount DECIMAL(12,2), "
          "status STRING, created_at TIMESTAMP, updated_at TIMESTAMP")

raw = (spark.read.schema(schema).option("mode", "DROPMALFORMED")
       .json(f"s3://myorg-lake-prod-bronze/sales/orders/ingest_date={ingest_date}/"))

latest = Window.partitionBy("order_id").orderBy(F.col("updated_at").desc())
silver = (raw.filter(F.col("order_id").isNotNull())
          .withColumn("rn", F.row_number().over(latest))
          .filter("rn = 1").drop("rn")
          .withColumn("status", F.lower(F.trim("status")))
          .withColumn("ingest_date", F.lit(ingest_date)))

(silver.write.mode("overwrite").partitionBy("ingest_date")
 .parquet("s3://myorg-lake-prod-silver/sales/orders_cleaned/"))

A few choices make this job reliable:

  • Explicit schema: declared types stop Spark from guessing differently from one file to the next. In production, prefer PERMISSIVE mode with a corrupt-record column, so malformed rows go to a quarantine path you can monitor instead of silently disappearing.
  • Deduplication: the window function keeps one row per order_id, the most recently updated.
  • Dynamic partition overwrite: only partitions present in the output are replaced, which makes the job idempotent.

For mutable entities like orders, a common next step is a current-state silver.orders table in Iceberg, maintained with MERGE INTO on order_id, so each order appears exactly once however often it changed.

Registering tables in the Glue Data Catalog

The Glue Data Catalog stores table definitions so that every engine sees the same schema. Crawlers are convenient for exploring bronze, but explicit DDL gives you control over schema changes in silver and gold. Athena partition projection also removes the need to register partitions: Athena calculates partition locations from table properties instead of looking them up.

CREATE EXTERNAL TABLE silver.orders_cleaned (
  order_id    string,
  customer_id string,
  amount      decimal(12,2),
  status      string,
  created_at  timestamp,
  updated_at  timestamp
)
PARTITIONED BY (ingest_date string)
STORED AS PARQUET
LOCATION 's3://myorg-lake-prod-silver/sales/orders_cleaned/'
TBLPROPERTIES (
  'projection.enabled' = 'true',
  'projection.ingest_date.type' = 'date',
  'projection.ingest_date.format' = 'yyyy-MM-dd',
  'projection.ingest_date.range' = '2024-01-01,NOW',
  'storage.location.template' = 's3://myorg-lake-prod-silver/sales/orders_cleaned/ingest_date=${ingest_date}/'
);

Gold: modeling for BI

Gold tables are shaped around how the business asks questions, not how source systems store data. Two patterns cover most needs:

  • Star schemas: fact tables of events or transactions, such as fact_orders, joined to dimension tables that describe them, such as dim_customer.
  • Aggregated tables: pre-computed summaries, such as daily revenue by region, that keep dashboards fast and cheap.

Athena CTAS (CREATE TABLE AS SELECT) queries build gold tables without a Spark job. Here silver.orders is the current-state table with one row per order:

CREATE TABLE gold.daily_revenue_by_region
WITH (
  format = 'PARQUET',
  write_compression = 'SNAPPY',
  external_location = 's3://myorg-lake-prod-gold/sales/daily_revenue_by_region/',
  partitioned_by = ARRAY['order_date']
) AS
SELECT c.region,
       SUM(o.amount)                       AS revenue,
       COUNT(DISTINCT o.order_id)          AS orders,
       CAST(DATE(o.created_at) AS varchar) AS order_date
FROM silver.orders o
JOIN silver.customers c ON o.customer_id = c.customer_id
GROUP BY c.region, CAST(DATE(o.created_at) AS varchar);

Partition columns must come last in the select list, and a single CTAS or INSERT INTO query can write at most 100 partitions, so build long histories in batches.

Permissions and cost controls

Lake Formation permissions

AWS Lake Formation sits on top of the Glue Data Catalog and adds database, table, column and row-level permissions, so you manage access with grants rather than complex bucket policies. A common model lets ingestion and transformation roles write to bronze and silver, lets analysts and BI tools read only gold, and hides sensitive columns such as email addresses from roles that do not need them. LF-tags, labels attached to databases, tables and columns, let you grant access by classification instead of table by table.

Cost controls

Storage on S3 is cheap, but careless querying is not. The levers that matter most:

  • Parquet plus partitions: Athena bills by data scanned, so columnar files and partition filters cut query costs dramatically.
  • Athena workgroups: a per-query data limit cancels runaway queries, and workgroup-level limits trigger alerts.
  • S3 lifecycle rules: move old bronze data to cheaper storage classes such as Glacier, and expire Athena query results after a few days.
  • Compaction: fewer, larger files mean fewer S3 requests and faster queries.
  • Right-sized Glue jobs: enable auto scaling, set job timeouts and run non-urgent jobs on the Flex execution class.

Key takeaways

  • Bronze keeps raw data for replay, silver enforces schema and quality, and gold serves business-ready models.
  • Use one S3 bucket per layer, Hive-style partitions and Parquet with Snappy or ZSTD from silver onward.
  • Write silver jobs that enforce explicit schemas, deduplicate records and overwrite only their own partitions.
  • Use Athena partition projection and Lake Formation grants to keep the catalog fast and access controlled.
  • Control costs with partition filters, workgroup limits, lifecycle rules and regular file compaction.
Portrait of Nandha Kumar

Written by

Nandha Kumar

Data Engineer & Full-Stack Developer in Chennai, building data platforms on AWS and Google Cloud.