High-throughput, production-grade Incremental Change Data Capture (CDC) and Star-Schema Analytical Data Warehouse Synchronization Engine.
Designed to substantiate the enterprise architecture mandate:
"Architected an enterprise data warehouse and automated Apache Airflow pipelines that removed real-time aggregation load from the main production database."
Running complex analytical aggregations (cohort retention, ARR rollups, multi-tenant metric breakdowns) directly against 3NF normalized OLTP production databases degrades operational performance, introduces table lock contention, and increases read latency for transactional users.
Airflow-WarehouseSync decouples transactional writes from analytical queries:
- Watermarked Incremental CDC: Dual-cursor non-blocking extraction (
(updated_at, id)) capturing delta mutations without full table scans. - Kimball Star-Schema Engine (DuckDB & PostgreSQL): Vectorized columnar OLAP storage with surrogate key mappings.
- Slowly Changing Dimensions (SCD Type 2): Point-in-time tracking for user attributes (e.g., plan/tier upgrades) preserving historical attribution.
- Pre-Aggregated Materialized Rollups: Sub-3ms query serving for real-time reporting dashboards.
- Zero-Downtime Expand/Contract Migrations: 4-phase schema evolution ensuring zero downtime across OLTP and OLAP pipelines.
flowchart TD
subgraph OLTP ["Production OLTP Database (3NF)"]
Users["oltp_users\n(Audit Timestamp + Version)"]
Courses["oltp_courses"]
Transactions["oltp_transactions"]
Watermarks["_cdc_watermarks\n(Table, Last TS, Last ID)"]
end
subgraph CDC ["CDC Extractor & Pipeline Orchestrator"]
DualCursor["Dual-Cursor Extractor\n(updated_at > TS OR id > ID)"]
Transformer["WarehouseTransformer\n(Surrogate Resolution + In-Memory Cache)"]
Appender["Vectorized Native Appender\n(DuckDB C++ Engine)"]
end
subgraph OLAP ["OLAP Data Warehouse (Star Schema)"]
DimUsers["dim_users\n(SCD Type 2: effective_start/end)"]
DimCourses["dim_courses\n(SCD Type 1)"]
DimDate["dim_date\n(Calendar Dimension)"]
FactTx["fact_transactions\n(Columnar Fact Table)"]
AggRevenue["agg_daily_revenue\n(Materialized Rollup)"]
end
Users --> DualCursor
Courses --> DualCursor
Transactions --> DualCursor
DualCursor --> Watermarks
DualCursor --> Transformer
Transformer --> Appender
Appender --> DimUsers
Appender --> DimCourses
Appender --> DimDate
Appender --> FactTx
FactTx --> AggRevenue
Simulated workload: 1,000 Users, 50 Course Catalogs, 30,000 Concurrent Transactions evaluated across OLTP 3NF vs. DuckDB Columnar Star-Schema:
| Metric | Direct OLTP (3NF Anti-Pattern) | DuckDB Star-Schema (OLAP) | Pre-Aggregated Rollup Table | Speedup |
|---|---|---|---|---|
| Multi-Table Aggregation Latency | 54.42 ms | 19.17 ms | 2.70 ms | 20.2x Faster |
| OLTP Lock Contention | Heavy (Read locks on active tables) | Zero (0 read locks) | Zero (0 read locks) | 100% Isolated |
| CDC ETL Ingestion Throughput | N/A | 6,321 records/sec | N/A | Sub-second sync |
| Data Quality / FK Orphan Rate | N/A | 0 orphans (100% integrity) | N/A | Verified |
erDiagram
dim_users ||--o{ fact_transactions : "user_key"
dim_courses ||--o{ fact_transactions : "course_key"
dim_date ||--o{ fact_transactions : "date_key"
fact_transactions ||--o{ agg_daily_revenue : "summarized into"
dim_users {
int user_key PK "Surrogate Key"
int user_id "Natural Key"
string tier "free | pro | enterprise"
string country
timestamp effective_start
timestamp effective_end
boolean is_current "SCD Type 2 Active Indicator"
}
dim_courses {
int course_key PK
int course_id "Natural Key"
string title
string category
int price_cents
boolean is_active
}
dim_date {
int date_key PK "YYYYMMDD"
date full_date
int year
int quarter
int month
boolean is_weekend
}
fact_transactions {
int transaction_key PK
int transaction_id "Natural Key"
int user_key FK
int course_key FK
int date_key FK
int amount_cents
string status
timestamp created_at
}
agg_daily_revenue {
int date_key PK
string category PK
string tier PK
bigint total_revenue_cents
int transaction_count
int unique_paying_users
}
High-throughput systems cannot execute ALTER TABLE ... DROP/RENAME COLUMN without table locks and downtime. This engine implements the standard 4-phase migration pattern:
- Phase 1: Expand
Adds the new column (tier_code) as nullable; establishes dual-write triggers or application hooks so all in-flight writes populate both legacy and new representations. - Phase 2: Backfill
Executes non-blocking, chunked batch updates (LIMIT 500) over legacy historical records without transaction locking. - Phase 3: Switch
Validates zero null values exist, transitions application read paths and CDC transforms to the new column. - Phase 4: Contract
Drops dual-write triggers, removes legacy columns during maintenance windows.
- Python 3.10+
duckdb>=1.0.0,pydantic>=2.0.0
$env:PYTHONPATH="."
python examples/run_warehouse_sync_demo.py$env:PYTHONPATH="."
python benchmarks/run_warehouse_benchmark.py$env:PYTHONPATH="."
pytest tests/ -vairflow-warehousesync/
├── benchmarks/
│ └── run_warehouse_benchmark.py # OLTP vs. OLAP latency & throughput benchmark
├── dags/
│ └── oltp_to_warehouse_sync_dag.py # Production Apache Airflow DAG definition
├── examples/
│ └── run_warehouse_sync_demo.py # End-to-end interactive demo
├── warehousesync/
│ ├── cdc/
│ │ ├── extractor.py # Dual-cursor watermarked CDC extractor
│ │ └── transformer.py # Dimension resolution & DuckDB appender
│ ├── migrations/
│ │ └── expand_contract.py # 4-phase zero-downtime schema migration
│ ├── models/
│ │ └── schema.py # Pydantic schemas for OLTP & OLAP
│ ├── olap/
│ │ └── warehouse.py # DuckDB Star-Schema & Rollup Engine
│ ├── oltp/
│ │ └── database.py # 3NF transactional database simulation
│ └── orchestrator.py # Pipeline runner with quality audits & metrics
├── tests/
│ ├── conftest.py
│ └── test_warehouse_sync.py # 6 unit & integration tests
├── docker-compose.yml # PostgreSQL OLTP + OLAP environment
└── pyproject.toml
Chethan Raj D S
Principal Solutions Architect & Technical Lead
- LinkedIn: linkedin.com/in/chethan-raj-b511ba1b
- GitHub: github.com/Chethan-Raj-D-S
- Email: chethanraj.d.s@gmail.com