How amine-labscraft/walmart_streaming_flow works
Purpose and entry points
This is a retail streaming-to-lakehouse pipeline: continuously generated PostgreSQL orders are incrementally ingested into Databricks, transformed with dbt, certified by Airflow quality gates, and served to Power BI.
Operational entry points:
• Flask Order Pulse UI: Walmart Data Engineering/Walmart dataset/generator_web_app.py
• Transactional generator: Walmart Data Engineering/Walmart dataset/continuous_order_generator.py
• Source schema deployment/loading: Walmart Data Engineering/deploy_raw_schema.py, Walmart Data Engineering/Walmart dataset/load_data.py
Analytical entry point:
• Hourly Airflow DAG: airflow/dags/orchestration.py
1. Transactional source and CDC boundary
Ghost PostgreSQL is the system of record, with normalized customers, stores, employees, products, orders, and order items. The generator selects valid active references and writes each order header plus 1–5 lines atomically; it does not invoke analytics services.
CDC is based on monotonic change_version for mutable order entities, assigned by source SQL sequence/triggers. This separates reliable technical ordering from business timestamps.
• Walmart Data Engineering/Walmart dataset/ddl/walmart_schema.sql
• Walmart Data Engineering/Walmart dataset/ddl/001_streaming_source_upgrade.sql
• Walmart Data Engineering/Walmart dataset/continuous_order_generator.py
2. Independent operational control surface
The Flask application lets users start/stop continuous generation and choose customer mode. It is a local operational UI over the Python generator and PostgreSQL connection, not the platform orchestration layer.
• Walmart Data Engineering/Walmart dataset/generator_web_app.py
• Walmart Data Engineering/Walmart dataset/templates/generator_index.html
• Walmart Data Engineering/Walmart dataset/static/generator_app.js
3. Airflow orchestration control plane
Airflow serializes the analytical lifecycle: trigger/poll a remote Databricks CDC job, clean dbt artifacts, build and test Silver Technical, build/test Silver Business, snapshot Gold dimensions, then build/test the Gold fact. A failure prevents downstream publication.
It runs containerized with Airflow 3/CeleryExecutor, Redis as broker, and PostgreSQL as Airflow metadata storage.
• airflow/dags/orchestration.py
• airflow/docker-compose.yaml
• airflow/Dockerfile
4. Databricks ingestion and Bronze
Databricks owns ingestion from PostgreSQL into Delta Bronze tables. Airflow calls the configured Databricks job through its SDK and waits for success; the remote job is therefore a hard boundary outside this repository. Orders/items use version cursors, while reference entities use update timestamps.
• airflow/dags/orchestration.py
• airflow/walmart_dbt/models/sources/sources.yml
• airflow/walmart_dbt/tools/migrate_ingestion_cursor.py
5. dbt medallion transformation graph
dbt reads walmart.bronze, incrementally merges six source-aligned entities into Silver Technical, then joins them into the Silver Business order-line table (obt_b). Gold derives reusable ephemeral projections, timestamp-SCD snapshots for dimensions, and a materialized fact.
• airflow/walmart_dbt/models/silver_t/orders_t.sql
• airflow/walmart_dbt/models/silver_b/obt_b.sql
• airflow/walmart_dbt/models/gold/fact/fact_orders.sql
6. Gold contract and quality boundaries
fact_orders is at order-item grain; revenue and quantity are additive, while repeated order-header totals must not be summed. Five dbt snapshots retain historical dimension versions. dbt schema, relationship, reconciliation, and custom business tests gate promotion before BI refresh.
• airflow/walmart_dbt/models/gold/fact/fact_orders.yml
• airflow/walmart_dbt/snapshots/dim_customers.yml
• airflow/walmart_dbt/tests/assert_fact_order_totals.sql
7. Serving and observability
Databricks SQL Warehouse serves Gold to Power BI. Monitoring is a separate Docker Compose stack using Prometheus, Grafana, Loki, Alloy, Blackbox, and a custom Walmart exporter; dashboards cover pipeline health, freshness/quality, generator activity, and platform status.
• airflow/monitoring/docker-compose.monitoring.yml
• airflow/monitoring/exporters/walmart-exporter/app.py
• airflow/monitoring/grafana/dashboards/data-freshness-quality.json
Components 18
Transactional source
- Order generator · Atomically writes order headers and 1–5 order lines.
Walmart Data Engineering/Walmart dataset/continuous_order_generator.py - Source schema & CDC · Sequences and triggers assign monotonic change versions.
Walmart Data Engineering/Walmart dataset/ddl/001_streaming_source_upgrade.sql - Ghost PostgreSQL · Normalized retail entities and transactional orders.
Operational control
- Order Pulse UI · Local controls for generator state and customer mode.
Walmart Data Engineering/Walmart dataset/generator_web_app.py - Hourly analytical DAG · Serializes CDC, dbt builds, tests, snapshots, and fact publication.
airflow/dags/orchestration.py - Airflow Celery runtime · CeleryExecutor with Redis broker and metadata PostgreSQL.
airflow/docker-compose.yaml - dbt quality gates · Schema, relationship, business, and order-total checks gate promotion.
airflow/walmart_dbt/tests/assert_fact_order_totals.sql
Databricks lakehouse
- Remote CDC job · External job triggered and polled by Airflow.
airflow/dags/orchestration.py - Ingestion cursors · Version cursors for orders/items and timestamp cursors for references.
airflow/walmart_dbt/tools/migrate_ingestion_cursor.py - Bronze tables · Raw PostgreSQL entities in walmart.bronze.
airflow/walmart_dbt/models/sources/sources.yml - Silver Technical · Six source-aligned entities merged from Bronze.
airflow/walmart_dbt/models/silver_t/orders_t.sql - Silver Business OBT · Joined business order-line table.
airflow/walmart_dbt/models/silver_b/obt_b.sql - Gold dimensions · Five timestamp-SCD dimension histories.
airflow/walmart_dbt/snapshots/dim_customers.yml - fact_orders · Materialized at order-item grain.
airflow/walmart_dbt/models/gold/fact/fact_orders.sql
Serving & monitoring
- Databricks SQL Warehouse
- Power BI
- Observability stack · Prometheus, Grafana, Loki, Alloy, Blackbox, and custom exporter.
airflow/monitoring/docker-compose.monitoring.yml - Walmart exporter · Exposes pipeline, freshness, quality, and generator metrics.
airflow/monitoring/exporters/walmart-exporter/app.py
Connections 20
- Order Pulse UI → Order generator: starts/stops
- Order generator → Ghost PostgreSQL: writes orders
- Source schema & CDC → Ghost PostgreSQL: defines CDC
- Airflow Celery runtime → Hourly analytical DAG: executes
- Hourly analytical DAG → Remote CDC job: triggers and polls
- Ghost PostgreSQL → Remote CDC job: CDC source
- Ingestion cursors → Remote CDC job: cursor state
- Remote CDC job → Bronze tables: ingests
- Bronze tables → Silver Technical: incremental merge
- Silver Technical → Silver Business OBT: joins entities
- Silver Business OBT → Gold dimensions: snapshots dimensions
- Silver Business OBT → fact_orders: builds fact
- Hourly analytical DAG → dbt quality gates: runs after each stage
- dbt quality gates → fact_orders: gates publication
- Gold dimensions → fact_orders: dimension history
- fact_orders → Databricks SQL Warehouse: serves Gold
- Databricks SQL Warehouse → Power BI: BI queries
- Walmart exporter → Observability stack: metrics
- Hourly analytical DAG → Walmart exporter: pipeline telemetry
- Order generator → Walmart exporter: generator telemetry