ETL pipeline that syncs data from PostgreSQL to ClickHouse every 30 minutes using Apache Spark.
Transfer new and updated records from app_user_visits_fact table:
- Source: PostgreSQL (OLTP)
- Destination: ClickHouse (OLAP)
- Method: Incremental loading based on
updated_attimestamp
PostgreSQL → Spark (reads WHERE updated_at > checkpoint) → ClickHouse
The pipeline:
- Reads last checkpoint timestamp
- Fetches only new/updated records from PostgreSQL
- Writes to ClickHouse
- Updates checkpoint
spark_app.py- Main Spark applicationclickhouse_schema.sql- ClickHouse table DDLsample_data.sql- Sample data for referenceREADME.md- This file
## Key Design Decisions
**Why `updated_at` instead of `created_at`?**
Records can be updated after creation (points spent, status changes). Using `updated_at` ensures we capture all changes.
**Why ReplacingMergeTree?**
Automatically handles duplicates by keeping the latest version based on `updated_at`.
**Why Batch (30 min) instead of Streaming?**
Simpler architecture, meets requirements, sufficient for analytics use case.
## Requirements
- Python 3.8+
- Apache Spark 3.5+
- PostgreSQL JDBC Driver
- ClickHouse JDBC Driver
---
**Author**: Ahmed Mohamed El-Slayed
**Contact**: shabaik1996@gmail.com