One source of truth for a retail team

A personal project modelled on a small online shop: five data sources, one warehouse, and metrics that mean the same thing in every dashboard.

Type
Personal project
Stack
Airflow, dbt, Snowflake, Python, SQL, Power BI
Focus
Analytics engineering

How it works

  1. Load each source

    Airflow runs one DAG per source every morning and lands the data in raw schemas, unchanged.

  2. Model in layers

    dbt builds staging models per source, then marts: fct_orders, dim_customers and revenue_weekly.

  3. Test every run

    Unique, not-null, relationship and freshness tests run after each load; a failure stops the models downstream.

  4. Serve one set of metrics

    Power BI reads the marts, and metric definitions live in one place in dbt.

revenue_weekly.sql
-- models/marts/revenue_weekly.sql
select
    date_trunc('week', ordered_at)  as week,
    sum(amount_net)                 as revenue,
    count(distinct customer_id)     as customers
from {{ ref('fct_orders') }}
where status = 'completed'
group by 1

Decisions I made. Each one is a trade-off, written down.

raw.* -> stg_* -> marts

Raw data stays untouched

Raw schemas are never edited. Every fix happens in staging, so any day can be rebuilt from source.

dbt build --select +revenue_weekly

Tests as the contract

Each model ships with its tests, and a failing test stops everything built on top of it.

metrics: revenue, active_customers

Metrics defined once

Revenue and active customers are defined in dbt, so dashboards read them instead of computing their own.