{"id":31039181,"url":"https://github.com/ehsanmanafi/bigdata-sampleflow","last_synced_at":"2025-09-14T07:50:40.548Z","repository":{"id":313628835,"uuid":"1052078164","full_name":"ehsanmanafi/BigData-SampleFlow","owner":"ehsanmanafi","description":"To simplify and make a  Big Data Analysis ","archived":false,"fork":false,"pushed_at":"2025-09-07T11:29:05.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-07T13:14:01.722Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ehsanmanafi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-07T11:07:25.000Z","updated_at":"2025-09-07T11:29:09.000Z","dependencies_parsed_at":"2025-09-07T13:14:13.568Z","dependency_job_id":"05cecc87-fd6b-4b3b-8669-972d6a35e291","html_url":"https://github.com/ehsanmanafi/BigData-SampleFlow","commit_stats":null,"previous_names":["ehsanmanafi/bigdata-sampleflow"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/ehsanmanafi/BigData-SampleFlow","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsanmanafi%2FBigData-SampleFlow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsanmanafi%2FBigData-SampleFlow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsanmanafi%2FBigData-SampleFlow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsanmanafi%2FBigData-SampleFlow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ehsanmanafi","download_url":"https://codeload.github.com/ehsanmanafi/BigData-SampleFlow/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehsanmanafi%2FBigData-SampleFlow/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275076569,"owners_count":25401316,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-14T02:00:10.474Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-14T07:50:39.651Z","updated_at":"2025-09-14T07:50:40.529Z","avatar_url":"https://github.com/ehsanmanafi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spark Streaming + Delta Lake + ClickHouse Pipeline\n\nThis project contains three Spark jobs that together implement a **Lambda-style data pipeline** with both **streaming (speed layer)** and **batch (batch layer)** processing.\n\n---\n\n## 📂 Jobs Overview\n\n### **Job1 – Kafka → Delta (Streaming Ingestion)**\n- Reads raw transaction events from **Kafka** in real time.\n- Parses JSON messages, applies basic cleaning (e.g., drop nulls, parse timestamps).\n- Writes the cleaned stream to **Delta Lake** (`/datalake/transactions_clean`).\n- Uses a **checkpoint** to maintain streaming state.\n\n### **Job2 – Delta → Model → ClickHouse (Realtime Scoring)**\n- Reads the **cleaned Delta stream** (output of Job1).\n- Loads a **Logistic Regression model** if available.\n- Applies the model for **real-time predictions** on each micro-batch.\n- Writes prediction results into **ClickHouse** (`transactions_realtime` table).\n\n### **Job3 – Batch Training \u0026 Batch Scoring**\n- Reads **historical data** from Delta Lake (batch mode).\n- Performs **feature engineering** and trains a **Logistic Regression model**.\n- Saves/overwrites the model at `/models/lr_model` so Job2 can use it for inference.\n- Optionally runs **batch predictions** and writes them to ClickHouse (`transactions_batch` table).\n\n---\n\n## 🔄 Workflow (How They Fit Together)\n\n1. **Job1** ingests Kafka events → cleans → stores in Delta Lake.  \n2. **Job2** consumes Delta Lake in streaming mode → applies ML model → stores predictions in ClickHouse (realtime layer).  \n3. **Job3** periodically trains/retrains the model with batch data → saves model → also writes batch predictions to ClickHouse (batch layer).  \n\nThis design follows the **Lambda Architecture** pattern:  \n- **Speed Layer** = Job1 + Job2 (low-latency, real-time scoring).  \n- **Batch Layer** = Job3 (accurate model training on historical data).  \n- **Serving Layer** = ClickHouse (query-ready predictions).  \n\n---\n\n## ⚙️ Requirements\n\n- **Apache Spark** (with PySpark and Structured Streaming)\n- **Delta Lake** (Delta Core libraries available on Spark)\n- **Kafka** (as the event source)\n- **ClickHouse** (for storing predictions)\n- **Python MLlib** (for Logistic Regression training)\n\n---\n\n## 🚀 How to Run\n\n### 1) Start Kafka and produce transaction events\nEnsure Kafka broker is running at `localhost:9092` and topic `transactions` exists.\n\n### 2) Run Job1 (Ingestion)\n```bash\nspark-submit job1_kafka_to_delta.py\n```\n\n### 3) Run Job2 (Realtime Scoring)\n```bash\nspark-submit job2_realtime_scoring.py\n```\n\n### 4) Run Job3 (Batch Training)\n```bash\nspark-submit job3_batch_training.py\n```\n\nJob3 should be scheduled (e.g., daily) to retrain the model and refresh predictions.\n\n---\n\n## 📌 Notes\n- Job1 and Job2 are **streaming jobs** and run continuously until stopped.  \n- Job3 is a **batch job** and finishes after training and writing results.  \n- Delta Lake ensures ACID storage in the Data Lake.  \n- Checkpoints are used only in streaming jobs (Job1 and Job2).  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fehsanmanafi%2Fbigdata-sampleflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fehsanmanafi%2Fbigdata-sampleflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fehsanmanafi%2Fbigdata-sampleflow/lists"}