Project 02 · Lakehouse & analytics engineering

Telecom Billing Lakehouse

A medallion lakehouse over synthetic Call Detail Records: partitioned Parquet in, Bronze/Silver/Gold out, three Airflow DAGs, a Great Expectations contract at the boundary, and eight dbt models with 41 tests — all runnable on a laptop.

$ make demo
Wrote 49998 CDRs across 3 day partitions to data/raw
        Medallion row counts         
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃ Layer                    ┃   Rows ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│ Bronze                   │ 49,998 │
│ Silver                   │ 49,998 │
│ Gold / revenue_by_market │     15 │
│ Gold / arpu_monthly      │      5 │
│ Gold / churn_signals     │ 49,998 │
└──────────────────────────┴────────┘
Demo complete. See data/{bronze,silver,gold}/.
Captured by scripts/measure.py · Oct 2026 · seed 42

At a glance

At a glance

Problem
Builds a single source of truth for revenue, ARPU, and churn signals over high-volume Call Detail Record data.
Approach
Three Airflow DAGs move raw CDR parquet through Bronze and Silver; dbt builds the Gold marts with 41 tests; Terraform provisions the AWS variant.
Run it
cd project-telecom-lakehouse && make install && make demo
Tests
8 passing · CI on every push
Docs
README (opens in new tab) Architecture (opens in new tab) Terraform (opens in new tab)

What exists — honestly

Status key →
  • CDR generator → partitioned Parquet

    49,998 rows across 3 day partitions

    Implemented
  • Medallion transform (DuckDB)

    raw → Gold timed in-process

    Measured
  • 8 dbt models with 41 tests

    dbt build, dbt-duckdb

    Measured
  • Great Expectations Bronze contract

    10 expectations defined; checkpoint stubbed

    Stub
  • Three Airflow DAGs (hourly, hourly, daily)

    docker compose: Airflow + MinIO

    Needs infra
  • Terraform: S3 buckets + Glue catalog

    terraform validate + fmt in CI

    Implemented
  • Iceberg tables

    target format; demo writes Parquet

    Planned
  • Churn signals mart

    degenerate on current synthetic data

    Implemented
Measured

0.24s

raw → Gold, 49,998 CDRs

median of 5 in-process runs · DuckDB

How this was measured
Method
make demo, then scripts/artifacts/telecom.py times raw_to_bronze → bronze_to_silver → silver_to_gold
Date
2026-10-05
Env
4 vCPU · Python 3.11.15 · seed 42
Evidence ledger
Measured

41/41

dbt tests passing

8 models · bronze → gold

How this was measured
Method
dbt build (dbt-duckdb, scratch profile) over make demo output
Date
2026-10-05
Env
4 vCPU · Python 3.11.15 · seed 42
Evidence ledger
Defined Caveat

10

Bronze contract expectations

types · nulls · ranges · MSISDN regex

How this was measured
Method
count of great_expectations/expectations/cdr_bronze_suite.json
Date
2026-10-05
Env
4 vCPU · Python 3.11.15 · seed 42

Caveat · Defined in the suite; the transform_silver DAG's checkpoint task is a stub, so the contract is not enforced at runtime yet.

Evidence ledger
Test run

8

unit tests passing

generator + transforms

How this was measured
Method
make test
Date
2026-10-05
Env
4 vCPU · Python 3.11.15 · seed 42
Evidence ledger

Re-measured Oct 2026 from the project's own make targets on synthetic data (seed 42) — full ledger and transcripts.

Medallion layers

Bronze, Silver, Gold — from the real run

Row counts, schemas and sample rows come straight from the Parquet that make demo wrote, read back with DuckDB. Pick a layer to see what it does and what guards it.

What this layer does

  • Reads raw Parquet with hive partitioning on ingest_date
  • Casts types, upper-cases call_type and market, nulls empty callee
  • Keeps every row so corrections can be replayed

What guards it

  • 10 Great Expectations rules (defined; checkpoint stubbed)
  • 9 dbt tests on br_cdr and br_account_register

bronze/cdr.parquet 49,998 rows · 11 columns

bronze/cdr.parquet: schema and sample rows
cdr_id varchar caller_msisdn varchar callee_msisdn varchar start_time timestamp duration_sec integer bytes_used bigint call_type varchar market varchar plan_id varchar is_roaming boolean ingest_date date
uuid4…+1••••••8136+1••••••4380D2 22:52:39140VOICEEASTPRO_25GBfalseD2
uuid4…+1••••••1090+1••••••3054D1 08:20:3300SMSSOUTHUNLIMITEDfalseD1
uuid4…+1••••••7272+1••••••4101D1 19:16:372810VOICECENTRALBASIC_5GBfalseD1
uuid4…+1••••••3231nullD2 18:50:58029590767DATACENTRALPRO_25GBfalseD2

Real make demo output read with DuckDB. MSISDNs are masked, cdr_id (a random uuid4) is redacted, and dates are shown as partition offsets (D1..D3) because the generator stamps rows relative to the run date.

Gold output: daily revenue by market

gold/revenue_by_market from make demo — 5 markets × 3 day partitions.

Real make demo output. Real make demo output read with DuckDB. MSISDNs are masked, cdr_id (a random uuid4) is redacted, and dates are shown as partition offsets (D1..D3) because the generator stamps rows relative to the run date.
Daily revenue by market (USD)
MarketDay 1Day 2Day 3Events (3 days)
CENTRAL541.07536.63540.9510039
EAST515.00542.30559.049979
NORTH543.69528.91533.249928
SOUTH571.47532.89551.9010042
WEST550.63560.86545.4410010
TakeawayTotals range only from $1.6k (NORTH) to $1.7k (WEST) over three days: the generator assigns markets uniformly, so the flat shape is a property of the synthetic data, not an insight.

Gold output: daily revenue by market

gold/revenue_by_market from make demo — 5 markets × 3 day partitions.

Totals range only from $1.6k (NORTH) to $1.7k (WEST) over three days: the generator assigns markets uniformly, so the flat shape is a property of the synthetic data, not an insight.

Orchestration

Three DAGs, parsed from the repo

Schedules, retries and tasks are read from the DAG files at build time. The Python tasks call the same functions make demo runs, so the local path and the orchestrated path can't drift apart.

DAG 2 of 3

@hourly

transform_silver

Bronze -> Silver normalization with GE data contracts

Owner
data-platform
Retries
1 · 2 minutes apart
Catchup
false
  1. great_expectations_bronze PythonOperator stub

    run_great_expectations()

    Loads the GE context and prints; no checkpoint runs yet.

  2. bronze_to_silver PythonOperator

    run_bronze_to_silver()

dags/transform_silver.py ↗ (opens in new tab)

DAG 3 of 3

@daily

build_gold_marts

Run dbt to build Gold marts and dbt test to validate them

Owner
data-platform
Retries
1 · 2 minutes apart
Catchup
false
  1. dbt_run_gold BashOperator

    cd /opt/airflow/dbt_telecom && dbt run --profiles-dir /opt/airflow/dbt_telecom --select gold

  2. dbt_test_gold BashOperator

    cd /opt/airflow/dbt_telecom && dbt test --profiles-dir /opt/airflow/dbt_telecom --select gold

dags/build_gold_marts.py ↗ (opens in new tab)
A day of scheduled runs UTC · each tick = one scheduled run
ingest_cdr_bronze
transform_silver
build_gold_marts

Takeaway The schedules are independent — no sensors or Datasets connect them, so Gold rebuilds at midnight whether or not Silver changed. Airflow Datasets would make that dependency explicit.

dbt lineage

Trace any model upstream and down

The graph is built from the models' own ref() and source() calls. Select a model to light up its lineage and read its SQL; press Esc to clear.

dbt_telecom · 8 models, 41 tests

Parsed from the dbt project

relationships test

Contracts & tests

What's checked, and where

dbt tests guard every model and all pass in the measured run. The Great Expectations suite specifies the Bronze contract; wiring its checkpoint so a failure blocks Silver is the open item.

dbt test surface

Every declared test by model and type, from the schema.yml files.

41/41 passing
Model not nulluniqueaccepted valuesrelationshipsexpression is true Total
raw.cdr_raw 311·· 5
br_account_register 21··· 3
br_cdr 312·· 6
sl_account_daily 3··1· 4
sl_cdr_clean 211·2 6
sl_revenue_event 11··1 3
arpu_monthly 3·1·1 5
churn_signals 211·· 4
revenue_by_market 3·1·1 5
All 226715 41

Bronze contract · cdr_bronze_suite

Bronze data contract for CDR ingest. Failures should block the silver build.

Defined · not enforced
  1. 01

    Table has exactly these 11 columns

    expect_table_columns_to_match_set

  2. 02

    cdr_id is never null

    expect_column_values_to_not_be_null

  3. 03

    cdr_id is unique

    expect_column_values_to_be_unique

  4. 04

    caller_msisdn is never null

    expect_column_values_to_not_be_null

  5. 05

    caller_msisdn matches ^\+1[0-9]{10}$

    expect_column_values_to_match_regex

  6. 06

    call_type ∈ {VOICE, SMS, DATA}

    expect_column_values_to_be_in_set

  7. 07

    market ∈ {NORTH, SOUTH, EAST, WEST, CENTRAL}

    expect_column_values_to_be_in_set

  8. 08

    plan_id ∈ {BASIC_5GB, PRO_25GB, UNLIMITED, FAMILY_50GB, PREPAID}

    expect_column_values_to_be_in_set

  9. 09

    0 ≤ duration_sec ≤ 86,400

    expect_column_values_to_be_between

  10. 10

    0 ≤ bytes_used ≤ 100,000,000,000

    expect_column_values_to_be_between

Expectations are defined in the suite. The transform_silver DAG loads the GE context but does not run a checkpoint, so enforcement is stubbed.

Architecture

What runs where

Each lane is a path through the system, colour-coded by status. Every node names the file that implements it — click through to the source.

Local medallion path

Measured

make demo + dbt build — DuckDB, no cloud account

  1. CDR generator

    50k rows, 3 day partitions

    generate_cdrs.py — data_generator/generate_cdrs.py (opens in new tab)
  2. Raw Parquet

    partitioned by ingest_date

    data/raw/

  3. Bronze

    typed, normalised

    transform.py — src/lakehouse/transform.py (opens in new tab)
  4. Silver

    valid rows, billable minutes / MB

    transform.py — src/lakehouse/transform.py (opens in new tab)
  5. Gold marts

    revenue · ARPU · churn

    transform.py — src/lakehouse/transform.py (opens in new tab)
  6. dbt build

    8 models, 41 tests

    dbt_telecom/ — dbt_telecom/ (opens in new tab)

Orchestrated path

Needs infra

docker compose: Airflow 2.9 (LocalExecutor), Postgres, MinIO

  1. MinIO raw zone

    S3-compatible landing

  2. ingest_cdr_bronze

    @hourly · PythonOperator · 2 retries

    ingest_cdr_bronze.py — dags/ingest_cdr_bronze.py (opens in new tab)
  3. transform_silver

    @hourly · GE check → bronze_to_silver

    transform_silver.py — dags/transform_silver.py (opens in new tab)
  4. build_gold_marts

    @daily · dbt run → dbt test

    build_gold_marts.py — dags/build_gold_marts.py (opens in new tab)

Bronze data contract

Stub

10 expectations defined; the DAG task loads GE but runs no checkpoint

  1. cdr_bronze_suite

    columns · nulls · regex · sets · ranges

    expectations/ — great_expectations/expectations/ (opens in new tab)
  2. Checkpoint gate Planned

    would block Silver on failure

AWS infrastructure

Implemented

Terraform — validated and fmt-checked in CI, not applied here

  1. S3 × 4

    raw · bronze · silver · gold; versioned, encrypted, private

    s3.tf — terraform/s3.tf (opens in new tab)
  2. Glue catalog

    database + cdr_bronze (Parquet)

    glue.tf — terraform/glue.tf (opens in new tab)
  3. Iceberg tables Planned

    target table format

Engineering narrative

Problem, judgment calls, and results

Problem

Telecom billing teams sit on enormous CDR (Call Detail Record) volumes and need a single source of truth for revenue, ARPU, and churn signals. The Medallion pattern — Bronze raw, Silver cleaned and rated, Gold consumption-ready — keeps late-arriving data and vendor corrections replayable while exposing only clean marts to BI. This project implements the whole path: a synthetic CDR generator, three Airflow DAGs, S3-compatible storage, a Great Expectations contract at the Bronze boundary, eight dbt models, and Terraform for the AWS variant — all runnable locally without an AWS account.

Judgment calls

Why medallion over a single table? Keeping Bronze append-only means a schema change, a parsing bug, or a vendor correction can be replayed without re-ingesting from upstream. Silver is where typing, validity filters, and rating (billable minutes and megabytes) happen. Gold is the only layer BI tools read.

Iceberg as the target, Parquet today. Iceberg’s hidden partitioning and partition evolution make schema migrations less painful, and it keeps tables portable to Trino or Athena, so it is the design target for a batch-first billing workload read by several engines. The runnable demo writes plain Parquet through DuckDB and the Terraform Glue table is Hive-style Parquet; moving to Iceberg tables is the documented next step, not a claim.

A contract at Bronze, tests at Silver and Gold. The Great Expectations suite specifies what may enter the lake — exact column set, non-null keys, the ^\+1[0-9]{10}$ MSISDN pattern, accepted values, numeric ranges. dbt tests then guard what the models produce — uniqueness, accepted values, non-negative revenue, and a relationships check from Silver back to the account register. Honest caveat: the transform_silver DAG loads the GE context but does not run a checkpoint yet, so the contract is defined and version-controlled but not enforced at runtime.

Independent schedules, on purpose for now. Ingest and Silver run hourly and Gold daily, each as its own DAG with retries. Nothing links them yet; production would add Airflow Datasets so Gold rebuilds only when Silver has actually changed.

Measured results

make demo takes 49,998 synthetic CDRs across 3 daily partitions from raw parquet through Bronze, Silver, and three Gold marts; the transform itself runs in 0.24s (median of 5 in-process runs on DuckDB). dbt build over the same raw data builds all 8 models and passes 41/41 tests. The project vendors local replacements for its two dbt_utils macros, so it runs completely offline.

One result is a finding rather than a success: the generator draws a fresh random MSISDN for every record, so each caller appears exactly once and the churn_signals mart classifies every caller as high risk. The SQL is right; the synthetic data isn’t shaped for it. The fix — a fixed subscriber pool — belongs in the generator.

What I would do differently in production

  • Run the GE checkpoint for real (or move to GE 1.x / pandera) so a broken contract blocks the Silver build.
  • Link the DAGs with Airflow Datasets and emit OpenLineage from every task and dbt run.
  • Add cross-column contracts (e.g. roaming only on roaming-eligible plans).
  • Replace LocalExecutor with KubernetesExecutor for scale-out.
  • Add an Iceberg compaction DAG to keep Bronze file counts bounded.

Stack

What it uses, and why

Apache Airflow 2.9
Three DAGs (hourly ingest, hourly Silver, daily Gold) with retries; LocalExecutor in docker compose.
DuckDB
Runs the same Bronze → Silver → Gold SQL locally in well under a second — no cluster.
dbt (dbt-duckdb)
Eight models and 41 tests; dbt_utils macros vendored so it builds fully offline.
Great Expectations
Bronze data contract: column set, nulls, MSISDN regex, accepted values, ranges.
MinIO / S3
S3-compatible landing zone locally; the same paths map to real buckets on AWS.
Terraform
Four encrypted, versioned, private S3 buckets plus a Glue catalog; validated in CI.
esc