How the platform works end to end: where every byte lives, how data moves and changes from source to report, how we run and maintain it, how developers connect to each part, and how to extend it safely.
sde_bronzeData residency and governance appear throughout. Each lineage slide names the physical location of the data at that step, and Part 3 covers the controls in one place.
Six moving parts, one storage layer, no servers. The only bill is AWS. Everything else is open source or free.
| Goal or constraint | How it is met |
|---|---|
| Modern but simple | dlt, S3 + Iceberg, Glue, Athena, dbt, Power BI. GitHub Actions schedules them |
| Real and mock data | Two free public APIs plus a deterministic retail generator |
| Open table format | Every layer is Apache Iceberg (Parquet, zstd) on S3 |
| Medallion in dbt | Bronze (raw) → silver (clean) → gold (star schema) |
| BI as the front end | Power BI Desktop imports gold through Athena ODBC |
| Only AWS costs money | ≈ $1–2 per month at demo scale; GitHub within its free quotas |
Stored once in S3, catalogued once in Glue, queried only through Athena. No copy of the data exists outside the bucket except the Power BI import and short-lived query results.
Every AWS resource is in infra/terraform. Three workflows schedule, test and publish. There is no orchestrator to host.
An OIDC role for automation, and IAM users for BI (gold only), analysts (read all, write sandbox) and data admin. Each identity queries through its own guarded workgroup.
Left to right is the data plane. The bands below show which tool moves the data at each hop, and which identity it runs as.
Generator in ingestion/mock, Frankfurter (ECB rates), Open-Meteo archive.
7 append-only Iceberg tables. Every row carries _dlt_load_id.
8 models. Typed, deduplicated, merged incrementally. Customer and product history.
2 facts, 4 dimensions, rebuilt in full each run. SCD2 customers.
Import mode. 6 tables, 6 relationships, 89 measures, 2 pages, 5 tooltips.
One lake bucket, one Glue catalog, one Athena workgroup per identity, each with a 1 GB scan cap and its own enforced result prefix.
pipeline daily at 05:30 UTC, ci on push and PR, docs after each pipeline. Auth to AWS by OIDC.
Bootstrap stack (state bucket, local state) and main stack (bucket, Glue, Athena, IAM, budget) with an S3 backend.
Same code runs locally and in CI. DBeaver over JDBC for ad-hoc SQL. Power BI Desktop for the model and report.
Durable copies of row-level data exist only in the S3 lake bucket in eu-west-1 (Ireland) and in the Power BI import on a workstation. Everything else is transient or metadata only.
Every place where project data can exist, what form it takes, how long it stays and who can read it. Use this table when you answer a data-protection or audit question.
| Location | Zone | Content | Form | Retention | Readable by |
|---|---|---|---|---|---|
| Frankfurter, Open-Meteo | External | Public reference data. They receive only dates, currency codes and city lat/lon | JSON over HTTPS | Theirs | Public |
| Runner disk | eu-west-1 | Mock rows, dlt load packages, dbt target/ | Parquet, JSON | Until the job ends | The workflow only |
sde_bronze_staging/ | S3 | dlt load files before the Iceberg insert | Parquet | 7 days (lifecycle) | Pipeline role, data admin |
sde_bronze/ | S3 | Raw rows, every load, plus _dlt_loads, _dlt_pipeline_state | Iceberg | Customer data 3 y; erasable | Pipeline, data admin; analyst without PII columns |
sde_silver/ | S3 | Clean, deduplicated rows and history versions | Iceberg | Customer data 3 y; erasable | Pipeline, data admin; analyst without PII columns |
sde_gold/ | S3 | Star schema for BI | Iceberg | Rebuilt each run | All four identities |
sde_sandbox/ | S3 | Analyst tables, views, UNLOAD files | Iceberg, Hive, CSV | Until the analyst drops it | Analyst, data admin |
athena-results/ | S3 | Result set of every query, including Power BI imports; one prefix per workgroup | CSV + metadata | 7 days (lifecycle) | Own prefix only (data admin: all) |
| Glue Data Catalog | AWS | Database and table definitions, S3 locations | Metadata | Lifetime of the table | Per database, by IAM |
ci_<run>_silver/gold | S3 + Glue | Full CI build from real bronze | Iceberg | Dropped at the end of the run | Pipeline role |
| Power BI import | Workstation | Full copy of the 6 gold tables, including customer columns | VertiPaq, cache.abf | Until deleted locally | Whoever has the file |
| Actions artifacts | GitHub | dbt run metadata and logs; dbt docs | JSON, HTML | 14 days | Repo readers |
| Terraform state | S3 | Resource configuration. No data, no secrets | JSON | 30 days of old versions | Admins |
Each S3 prefix matches a Glue database of the same name. Iceberg adds ACID commits, MERGE, schema evolution and time travel on plain Parquet files.
s3://sde-demo-lake-<account id>/sde_bronze/orders/ # dlt: {dataset}/{table} data/ *.parquet # row data, zstd metadata/ *.metadata.json, snap-*.avro, *-m0.avro sde_bronze_staging/orders/… # dlt load files, 7-day expiry sde_silver/slv_orders/<uuid>/ # dbt: schema_table_unique data/order_date_month=2026-11/*.parquet metadata/… sde_gold/fct_sales/<uuid>/… # partitioned by month(order_date) sde_sandbox/<table>/… # analyst-owned athena-results/sde-demo/ sde-demo-powerbi/ sde-demo-analyst/ # 7-day expiry
The dbt <uuid> suffix means a full rebuild writes to a new folder and swaps the Glue pointer, so readers never see a half-written table.
BucketOwnerEnforcedathena-results/ and sde_bronze_staging/ expire after 7 days; incomplete multipart uploads abort after 1 daysde_bronze, sde_bronze_staging, sde_silver, sde_gold, sde_sandbox, each with its S3 locationmetadata.json; Athena follows it to manifests and data filesci_<run id>_silver and _gold and drops them after the runEach source keeps its own high-water mark in dlt state, which lives in the bronze database. The state moves forward only when data really arrived.
A coffee and bakery chain: 49 stores in 36 cities across 8 countries, about 1,200 orders and 2,300 lines a day, in local currency.
(seed, entity, date, index), so any day regenerates identicallylast_generated_date; default end is yesterdayDaily reference rates, base EUR, for SEK, DKK, NOK, GBP, PLN and CHF. Business days only.
/v1/{first}..{today} per runlast_rate_date; rows from before first are droppedDaily min, max and mean temperature and precipitation from ERA5 reanalysis, about 5 days behind.
last_date_by_store; a new store backfills from SDE_START_DATEingestion/pipelines/run.py runs one dlt pipeline per source (sde_mock, sde_fx, sde_weather), all writing to the sde_bronze dataset.
_dlt_pipeline_state from bronze through AthenaS3 → runner_dlt_load_id, _dlt_idrunner disk_dlt_loads; new state saved with the packagesde_bronze/# ingestion/destination.py (simplified) destination = dlt.destinations.athena( query_result_bucket="s3://<lake>/athena-results/dlt/", athena_work_group="sde-demo") staging = dlt.destinations.filesystem(bucket_url="s3://<lake>") dlt.pipeline(pipeline_name=f"sde_{name}", destination=destination, staging=staging, dataset_name="sde_bronze") # every resource @dlt.resource(write_disposition="append", table_format="iceberg")
--refresh uses drop_sources: drops that source's tables and state, then reloads from SDE_START_DATEaws login or OIDC)Silver reads only bronze rows from loads newer than the newest one it has already merged, deduplicates them, then MERGEs them into Iceberg on the business key.
-- models/silver/slv_orders.sql {{ config(unique_key='order_id', partitioned_by=['month(order_date)']) }} with src as ( select * from {{ source('bronze', 'orders') }} {{ new_dlt_loads_only() }} ), ranked as ( select *, row_number() over ( partition by order_id order by updated_at desc, _dlt_load_id desc) as rn from src ) select order_id, store_id, customer_id, {{ to_ts('ordered_at') }} as ordered_at, …, lower(order_status) as order_status, cast(order_total as decimal(14,2)) as order_total, _dlt_load_id from ranked where rn = 1
-- macros/incremental.sql: what new_dlt_loads_only() renders to where cast(_dlt_load_id as double) > ( select coalesce(max(cast(_dlt_load_id as double)), 0) from sde_silver.slv_orders ) -- empty on the first run and on --full-refresh -- dbt_project.yml silver: +materialized: incremental +incremental_strategy: merge +on_schema_change: append_new_columns +table_type: iceberg +format: parquet +write_compression: zstd
_dlt_load_id (a unix-epoch string per run) is kept in every silver row. It links a silver row to the bronze load and the _dlt_loads entry it came from.
Types are cast explicitly, codes are upper-cased, emails lower-cased and trimmed, and timestamps are cast to timestamp(6) with to_ts(), which Iceberg needs.
All SQL runs in Athena. dbt on the runner only sends statements. Rows move from sde_bronze/ to sde_silver/ inside S3 and never pass through the runner.
Eight models in sde_silver. Seven are incremental MERGEs; the calendar-day FX table is a small full rebuild because late rates can fill earlier gaps.
| Model | From bronze | Unique key (MERGE) | Latest version wins by | Key transformations |
|---|---|---|---|---|
slv_stores | stores | store_id | updated_at, load id | Typed lat/lon, opened_date, upper-case codes |
slv_product_versions | products | product_id, price_version | updated_at, load id | Keeps every quarterly price version; valid_from = updated_at |
slv_customer_versions | customers | customer_id, updated_at | load id | Keeps every profile version; trims names, lower-cases email |
slv_orders | orders | order_id | updated_at, load id | Status lower-cased, money as decimal(14,2), partitioned by month |
slv_order_lines | order_lines | order_line_id | updated_at, load id | Quantity, unit price, discount and amount typed |
slv_fx_rates | fx_rates | rate_date, quote_currency | fetched_at, load id | ECB business days only: 1 EUR = rate × quote currency |
slv_fx_rates_daily | (slv_fx_rates) | table, full rebuild | – | Date spine to today; carries the last rate forward; adds EUR = 1.0; keeps source_rate_date |
slv_weather_daily | weather_daily | store_id, weather_date | fetched_at, load id | Renames to temp_*_c, precipitation_mm |
mock --refresh plus dbt build --full-refresh. A plain merge would keep the old rows.sde_goldSix tables, rebuilt in full on every run. At this size a rebuild costs fractions of a cent and keeps gold consistent with any SCD2 or FX correction upstream.
| Table | Grain | Built from | Notes |
|---|---|---|---|
fct_sales | Order line | slv_order_lines, slv_orders, slv_fx_rates_daily, slv_product_versions, dim_customer | Local and EUR amounts; cost at the price version valid at order time; net_revenue_eur and gross_margin_eur count completed orders only; partitioned by month(order_date) |
fct_daily_store_weather | Store × day | slv_weather_daily, fct_sales | Weather beside that day's completed orders, units and revenue; temperature bands; is_rainy_day at ≥ 1 mm |
dim_customer | Customer version | slv_customer_versions | SCD Type 2: valid_from, valid_to, is_current; md5 surrogate key; age band; unknown member '-1' for guests |
dim_product | Product | slv_product_versions | Type 1: current price version; product group (Beverages, Food, Retail) |
dim_store | Store | slv_stores | Country name, region (Nordics, Rest of Europe), currency |
dim_date | Day | Generated spine | 2025-01-01 to one year ahead; integer date_key yyyymmdd; ISO week, week and month boundaries, is_past |
Store and product use natural IDs as keys. Customers use md5(customer_id | updated_at).
6 single-direction many-to-one joins from the two facts to date, customer, product and store.
Each rebuild writes a new <uuid> folder under sde_gold/<table>/ and repoints Glue.
Power BI (reader user), DBeaver analysts, and analyst sandbox views that join gold.
Every arrow is a dbt ref() or source(), so this graph is also in the published dbt docs. Column headers show where each layer physically lives.
The columns most reports depend on, traced back to the source field. Joins are point-in-time: every lookup uses the order's own date or timestamp.
| fct_sales column | Rule | Comes from | Original source |
|---|---|---|---|
line_amount_local | As is | slv_order_lines.line_amount (decimal 14,2) | Generator · order_lines |
eur_rate | Join on order_date = rate_date and currency | slv_fx_rates_daily.eur_rate, last ECB rate on or before the day | Frankfurter · fx_rates |
line_amount_eur | line_amount / eur_rate, cast decimal(14,2) | Both rows above | Generator + ECB |
cost_eur | unit_cost_eur × quantity, version where valid_from ≤ ordered_at < valid_to | slv_product_versions (first version back-dated to 1900) | Generator · products |
customer_key | SCD2 join on customer_id and ordered_at; no match → '-1' | dim_customer ← slv_customer_versions | Generator · customers |
is_completed | order_status = 'completed' | slv_orders.order_status (lower-cased) | Generator · orders |
net_revenue_eur | line_amount_eur if completed, else 0 | Derived in gold | – |
gross_margin_eur | line_amount_eur − cost_eur if completed, else 0 | Derived in gold | – |
[Net Revenue] = SUM(fct_sales[net_revenue_eur]); the other 88 measures build on the same columns.slv_order_lines._dlt_load_id → _dlt_loads names the run that loaded it.A sale must carry the customer segment, product cost and exchange rate that applied when it happened, not today's values.
slv_customer_versionsvalid_to = the next version's updated_at, else 9999-12-31'-1'fct_sales builds [valid_from, valid_to) windows with lead()ordered_atdim_product itself is Type 1 (current price) for slicingsource_rate_date records which one-- fct_sales.sql: the point-in-time joins left join fx on o.order_date = fx.rate_date and l.currency_code = fx.currency_code left join product_versions pv on l.product_id = pv.product_id and o.ordered_at >= pv.valid_from and o.ordered_at < pv.valid_to left join customers c on o.customer_id = c.customer_id and o.ordered_at >= c.valid_from and o.ordered_at < c.valid_to
Import mode: a refresh runs one small Athena query per gold table and stores the result in the local model. Clicks on visuals never reach AWS.
select … from sde_gold.<table> in workgroup sde-demo-powerbiathena-results/sde-demo-powerbi/ (7 days, this user only), then streamed to Desktop.pbi/cache.abf on the workstationdim_date marked as date table; auto date/time offGranularity field parameter: Daily, Weekly, Monthly.pbip. Model and report are text in git; data never is. *.pbix and cache.abf are git-ignored because they embed the imported rows..github/workflows/pipeline.yml, cron 30 5 * * * (05:30 UTC, after the ECB publishes yesterday's rates). Concurrency group pipeline prevents overlapping runs; timeout 45 minutes.
sde-demo-github-pipelinerun.py mock fx weather into bronze; erased customers skippedprivacy.py apply; Sundays: the retention jobdbt build: silver MERGE, gold, 50 testsOPTIMIZE and VACUUM on silverdocs.yml builds the dbt-docs artifact (14 days)sources: e.g. "fx weather"full_refresh: rebuild silver from all of bronzemaintenance: force Iceberg housekeeping and the retention jobEvery push and pull request is checked twice: statically, and with a full dbt build against the real bronze data in throwaway databases. Production layers are never touched by CI.
ruff check and ruff format --checksqlfluff lint: Athena dialect, jinja templater, no DB neededpytest: generator determinism and shape, weather per city, Power BI report rulesdbt parse: the project compilesterraform fmt -check and validate on both stacksDBT_TARGET=cigenerate_schema_name writes to ci_<run id>_silver and ci_<run id>_golddrop_ci_schemas runs with if: always()dbt build --select <changed>+ci_*Tests run inside dbt build in DAG order. A failing test stops downstream models, so a broken silver table never reaches gold or Power BI.
loaded_at_field from _dlt_load_idunique and not_null on merge keysaccepted_values for order status, segment, currencyaccepted_range for prices, quantities, FX ratesrelationships from facts to every dimensionDLT_DATA_DIR: the second run must load nothingvalidate_pbir.py checks report JSON against Microsoft's schemasrun_results.json in the run's artifacts (14 days)Enforced by IAM in infra/terraform/iam.tf at three levels: Glue database or table ARNs, S3 prefixes, and the Athena workgroup. A leaked key exposes only that identity's scope.
| Identity | Credential | Bronze | Silver | Gold | Sandbox | Workgroups | Cannot |
|---|---|---|---|---|---|---|---|
| Pipeline role | OIDC, ≤ 1 h | read/write | read/write | read/write | read/write | sde-demo | Anything outside this project; drop non-ci_* databases |
| sde-demo-powerbi-reader | access key | none | none | read | none | sde-demo-powerbi only | See silver or bronze; write anything; read others' results |
| sde-demo-analyst | access key | read, no PII | read, no PII | read | full objects | sde-demo-analyst only | Change managed layers; create or drop databases; read others' results |
| sde-demo-data-admin | access key | full | full | full | full | any | IAM, billing, state bucket, bucket config, non-sde_* databases |
| Your admin user | aws login | full | full | full | full | any | Unrestricted (AdministratorAccess) |
The role trusts GitHub's immutable subject repo:<owner>@<id>/<repo>@<id>:*, so a renamed or re-created repo cannot assume it. Repo variables hold the role ARN; there are no secrets.
Terraform creates users and policies, never access keys. Keys are created with the CLI and live only in ~/.aws/credentials. Rotate yearly, at most two per user.
Each identity queries only through its own workgroup: enforced result prefix that only it can read, SSE-S3, 1 GB per-query scan cap, CloudWatch metrics.
The customer data is synthetic (Faker names, @example.com emails), but its shape is real personal data. We treat it as if it were real, so the controls carry over to production sources.
| Step | Physical location | Personal fields present | Copies kept | Who can read |
|---|---|---|---|---|
| Generated | Runner memory and dlt package on runner disk | first_name, last_name, email, city, birth_year, segment, opt-in | None after the job | Workflow |
| Staged | sde_bronze_staging/customers/ | All of the above | 7 days | Pipeline, data admin |
| Bronze | sde_bronze/customers/ | All, every version, every load | 3 y after last activity; erasable | Pipeline, data admin; analyst sees no names or email |
| Silver | sde_silver/slv_customer_versions/; customer_id also in slv_orders | All, every version, normalised | 3 y after last activity; erasable | Pipeline, data admin; analyst sees no names or email |
| Gold | sde_gold/dim_customer/ | No names or email. Keys, city, birth year, segment, opt-in, plus age_band | Rebuilt each run | All four identities |
| Query results | athena-results/<wg>/ | Whatever a query selected, including each Power BI import of dim_customer | 7 days | The identity that ran it, and the data admin |
| Power BI | Workstation: VertiPaq and .pbi/cache.abf | The 14 dim_customer columns; no names or email | Until deleted locally | Anyone with the file or PC |
Append-only bronze and Iceberg snapshots are great for lineage and recovery. So deleting a person's data is scripted: every layer, every snapshot, and the files in S3.
VACUUM per the table's vacuum_max_snapshot_age_secondsprivacy.py erase <id>sde_governance, which the analyst can't readOPTIMIZE + VACUUM: gone from snapshots and S3_dlt_loads: every load with status and timeAcceptable for a demo with synthetic data. Each item should be closed before a real personal-data source is connected.
| Gap | Risk | Severity | Recommended fix |
|---|---|---|---|
Shared athena-results/ prefix | The BI reader and analyst could read results of other identities' bronze or silver queries | Fixed | Done: one workgroup and result prefix per identity, IAM scoped to each |
| Names and emails in gold and Power BI | Direct identifiers copied to every workstation that refreshes | Fixed | Done: dropped from dim_customer and the Power BI model; they stay in silver |
| No column-level control | Analysts read every column of every layer | Fixed | Done: Lake Formation hybrid mode; pii-tagged columns hidden from the analyst |
| Bronze has no retention | Old profile versions kept forever | Fixed | Done: 3-year rules, weekly job, privacy.py erase with verification |
| Processing on GitHub-hosted runners | Rows exist briefly on VMs outside our chosen region | Fixed | Done: data jobs run on a CodeBuild runner in eu-west-1; only the owner's jobs start it |
| Long-lived access keys | Static keys on workstations | Medium | IAM Identity Center with short-lived sessions; keep keys only for the ODBC DSN |
| SSE-S3, not KMS | No key-level access control or key audit | Low | SSE-KMS with a customer-managed key and bucket keys |
| No data classification or catalog | Sensitivity lives in people's heads | Low | meta: {pii: true} in dbt YAML, surfaced in docs and synced to LF-tags |
The design scales in steps. Each step below adds one capability without replacing the core of S3, Iceberg, Glue, Athena and dbt.
_dlt_load_id links any gold row back to the load that brought itMore: the live report, the platform overview and the dbt lineage docs on the showcase site.