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}/. 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 →- Implemented
CDR generator → partitioned Parquet
49,998 rows across 3 day partitions
- Measured
Medallion transform (DuckDB)
raw → Gold timed in-process
- Measured
8 dbt models with 41 tests
dbt build, dbt-duckdb
- Stub
Great Expectations Bronze contract
10 expectations defined; checkpoint stubbed
- Needs infra
Three Airflow DAGs (hourly, hourly, daily)
docker compose: Airflow + MinIO
- Implemented
Terraform: S3 buckets + Glue catalog
terraform validate + fmt in CI
- Planned
Iceberg tables
target format; demo writes Parquet
- Implemented
Churn signals mart
degenerate on current synthetic data
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
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
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 ledger8
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
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.
Raw
49,998
3 partitions
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
| 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••••••4380 | D2 22:52:39 | 14 | 0 | VOICE | EAST | PRO_25GB | false | D2 |
| uuid4… | +1••••••1090 | +1••••••3054 | D1 08:20:33 | 0 | 0 | SMS | SOUTH | UNLIMITED | false | D1 |
| uuid4… | +1••••••7272 | +1••••••4101 | D1 19:16:37 | 281 | 0 | VOICE | CENTRAL | BASIC_5GB | false | D1 |
| uuid4… | +1••••••3231 | null | D2 18:50:58 | 0 | 29590767 | DATA | CENTRAL | PRO_25GB | false | D2 |
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.
What this layer does
- Drops rows without a caller, with negative duration, or an unknown call type
- Derives billable_minutes (ceil of seconds / 60, voice only) and billable_mb
- Normalises the roaming flag
What guards it
- 13 dbt tests incl. a relationships test back to the account register
silver/cdr.parquet 49,998 rows · 13 columns
| cdr_id varchar | caller_msisdn varchar | callee_msisdn varchar | start_time timestamp | duration_sec integer | billable_minutes double | bytes_used bigint | billable_mb double | call_type varchar | market varchar | plan_id varchar | is_roaming boolean | ingest_date date |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| uuid4… | +1••••••8136 | +1••••••4380 | D2 22:52:39 | 14 | 1 | 0 | 0 | VOICE | EAST | PRO_25GB | false | D2 |
| uuid4… | +1••••••1090 | +1••••••3054 | D1 08:20:33 | 0 | 0 | 0 | 0 | SMS | SOUTH | UNLIMITED | false | D1 |
| uuid4… | +1••••••7272 | +1••••••4101 | D1 19:16:37 | 281 | 5 | 0 | 0 | VOICE | CENTRAL | BASIC_5GB | false | D1 |
| uuid4… | +1••••••3231 | null | D2 18:50:58 | 0 | 0 | 29590767 | 28.22 | DATA | CENTRAL | PRO_25GB | false | D2 |
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.
What this layer does
- revenue_by_market: daily revenue at $0.05/billable min, $0.02/MB, $0.01/SMS
- arpu_monthly: average revenue per active caller, by plan and month
- churn_signals: per-caller activity bucketed into high / medium / low risk
What guards it
- 14 dbt tests: accepted values, non-null keys, revenue ≥ 0
Finding ·
all 49,998 callers land in high churn risk: the generator
draws a new MSISDN per record, so nobody has more than one event. The mart is
right; the synthetic data isn't shaped for it.
gold/revenue_by_market 15 rows · 4 columns
| market varchar | ingest_date date | revenue_usd double | event_count bigint |
|---|---|---|---|
| CENTRAL | D1 | 541.0676 | 3372 |
| CENTRAL | D2 | 536.6291 | 3326 |
| CENTRAL | D3 | 540.9509 | 3341 |
| EAST | D1 | 515.0003 | 3254 |
gold/arpu_monthly 5 rows · 4 columns
| month timestamp | plan_id varchar | arpu_usd double | active_callers bigint |
|---|---|---|---|
| M1 | BASIC_5GB | 0.1641 | 9926 |
| M1 | FAMILY_50GB | 0.1623 | 10085 |
| M1 | PREPAID | 0.1656 | 10176 |
| M1 | PRO_25GB | 0.1608 | 9913 |
gold/churn_signals 49,998 rows · 5 columns
| caller_msisdn varchar | last_event timestamp | events_30d bigint | roaming_events double | churn_risk varchar |
|---|---|---|---|---|
| +1••••••8136 | D2 22:52:39 | 1 | 0 | high |
| +1••••••1090 | D1 08:20:33 | 1 | 0 | high |
| +1••••••7272 | D1 19:16:37 | 1 | 0 | high |
| +1••••••3231 | D2 18:50:58 | 1 | 0 | high |
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.
| Market | Day 1 | Day 2 | Day 3 | Events (3 days) |
|---|---|---|---|---|
| CENTRAL | 541.07 | 536.63 | 540.95 | 10039 |
| EAST | 515.00 | 542.30 | 559.04 | 9979 |
| NORTH | 543.69 | 528.91 | 533.24 | 9928 |
| SOUTH | 571.47 | 532.89 | 551.90 | 10042 |
| WEST | 550.63 | 560.86 | 545.44 | 10010 |
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 1 of 3
@hourlyingest_cdr_bronze
Ingest raw CDR parquet into the Bronze Iceberg table
- Owner
- data-platform
- Retries
- 2 · 5 minutes apart
- Catchup
- false
-
raw_to_bronzePythonOperatoringest_to_bronze()
DAG 2 of 3
@hourlytransform_silver
Bronze -> Silver normalization with GE data contracts
- Owner
- data-platform
- Retries
- 1 · 2 minutes apart
- Catchup
- false
-
great_expectations_bronzePythonOperator stubrun_great_expectations()
Loads the GE context and prints; no checkpoint runs yet.
-
bronze_to_silverPythonOperatorrun_bronze_to_silver()
DAG 3 of 3
@dailybuild_gold_marts
Run dbt to build Gold marts and dbt test to validate them
- Owner
- data-platform
- Retries
- 1 · 2 minutes apart
- Catchup
- false
-
dbt_run_goldBashOperatorcd /opt/airflow/dbt_telecom && dbt run --profiles-dir /opt/airflow/dbt_telecom --select gold
-
dbt_test_goldBashOperatorcd /opt/airflow/dbt_telecom && dbt test --profiles-dir /opt/airflow/dbt_telecom --select gold
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 projectrelationships 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.
Every declared test by model and type, from the schema.yml files.
| Model | not null | unique | accepted values | relationships | expression is true | Total |
|---|---|---|---|---|---|---|
raw.cdr_raw | 3 | 1 | 1 | · | · | 5 |
br_account_register | 2 | 1 | · | · | · | 3 |
br_cdr | 3 | 1 | 2 | · | · | 6 |
sl_account_daily | 3 | · | · | 1 | · | 4 |
sl_cdr_clean | 2 | 1 | 1 | · | 2 | 6 |
sl_revenue_event | 1 | 1 | · | · | 1 | 3 |
arpu_monthly | 3 | · | 1 | · | 1 | 5 |
churn_signals | 2 | 1 | 1 | · | · | 4 |
revenue_by_market | 3 | · | 1 | · | 1 | 5 |
| All | 22 | 6 | 7 | 1 | 5 | 41 |
Bronze contract · cdr_bronze_suite
Bronze data contract for CDR ingest. Failures should block the silver build.
- 01
Table has exactly these 11 columns
expect_table_columns_to_match_set
- 02
cdr_id is never null
expect_column_values_to_not_be_null
- 03
cdr_id is unique
expect_column_values_to_be_unique
- 04
caller_msisdn is never null
expect_column_values_to_not_be_null
- 05
caller_msisdn matches ^\+1[0-9]{10}$
expect_column_values_to_match_regex
- 06
call_type ∈ {VOICE, SMS, DATA}
expect_column_values_to_be_in_set
- 07
market ∈ {NORTH, SOUTH, EAST, WEST, CENTRAL}
expect_column_values_to_be_in_set
- 08
plan_id ∈ {BASIC_5GB, PRO_25GB, UNLIMITED, FAMILY_50GB, PREPAID}
expect_column_values_to_be_in_set
- 09
0 ≤ duration_sec ≤ 86,400
expect_column_values_to_be_between
- 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
Measuredmake demo + dbt build — DuckDB, no cloud account
-
CDR generator
50k rows, 3 day partitions
generate_cdrs.py — data_generator/generate_cdrs.py (opens in new tab) -
Raw Parquet
partitioned by ingest_date
data/raw/
-
Bronze
typed, normalised
transform.py — src/lakehouse/transform.py (opens in new tab) -
Silver
valid rows, billable minutes / MB
transform.py — src/lakehouse/transform.py (opens in new tab) -
Gold marts
revenue · ARPU · churn
transform.py — src/lakehouse/transform.py (opens in new tab) -
dbt build
8 models, 41 tests
dbt_telecom/ — dbt_telecom/ (opens in new tab)
Orchestrated path
Needs infradocker compose: Airflow 2.9 (LocalExecutor), Postgres, MinIO
-
MinIO raw zone
S3-compatible landing
-
ingest_cdr_bronze
@hourly · PythonOperator · 2 retries
ingest_cdr_bronze.py — dags/ingest_cdr_bronze.py (opens in new tab) -
transform_silver
@hourly · GE check → bronze_to_silver
transform_silver.py — dags/transform_silver.py (opens in new tab) -
build_gold_marts
@daily · dbt run → dbt test
build_gold_marts.py — dags/build_gold_marts.py (opens in new tab)
Bronze data contract
Stub10 expectations defined; the DAG task loads GE but runs no checkpoint
-
cdr_bronze_suite
columns · nulls · regex · sets · ranges
expectations/ — great_expectations/expectations/ (opens in new tab) -
Checkpoint gate Planned
would block Silver on failure
AWS infrastructure
ImplementedTerraform — validated and fmt-checked in CI, not applied here
-
S3 × 4
raw · bronze · silver · gold; versioned, encrypted, private
s3.tf — terraform/s3.tf (opens in new tab) -
Glue catalog
database + cdr_bronze (Parquet)
glue.tf — terraform/glue.tf (opens in new tab) -
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.