This project implements a telco churn prediction pipeline with local Apache Airflow orchestration, native Apache Kafka streaming, and PySpark-based model training and inference.
- Python 3.9+
- Java 17+
- Apache Kafka 3.7+ installed natively
- uv package manager recommended
make installThis creates or uses .venv and installs the project dependencies.
make airflow-init
make airflow-startAirflow runs locally with the project-local metadata database in .airflow/. The UI is available at http://localhost:8080.
For Kafka installation and native KRaft setup steps, see kafka/README.md.
source setup_kafka_env.sh
make kafka-format
make kafka-start-bg
make kafka-topicsKafka topics used by this project are:
telco.raw.customerstelco.churn.predictionstelco.deadletter
- Open http://localhost:8080
- Trigger the desired DAG from the UI
Current DAG ids:
kafka_batch_consumer_dagkafka_consumer_streaming_dag
Batch processing:
make kafka-producer-batch
make kafka-consumerStreaming processing:
make kafka-consumer-continuous
make kafka-producer-streamThe streaming consumer now queues kafka_consumer_streaming_dag at the end of every non-empty inference cycle, so the Airflow UI gets a run as soon as a cycle finishes. The streaming producer also queues the same DAG after the stream run completes. If you prefer the alias used in the workflow, make kafka-produce-stream maps to make kafka-producer-stream.
make data-pipeline
make train-pipeline
make streaming-inferencemake kafka-start-bg
make kafka-stop
make kafka-topics
make kafka-producer-batch
make kafka-producer-stream
make kafka-produce-stream
make kafka-consumer
make kafka-consumer-continuous
make kafka-check
make kafka-resetmake airflow-init
make airflow-start
make airflow-kill
make airflow-reset
make airflow-health
make airflow-trigger-all
make airflow-trigger-kafka-batch-consumer
make airflow-trigger-kafka-consumer-streamingmake mlflow-ui
make kafka-sample-scored- Data ingestion from
data/raw/TelcoCustomerChurn.csv - Feature engineering and preprocessing in
src/ - Model training with PySpark via
make train-pipeline - Kafka event production to
telco.raw.customers - Continuous or batch inference through Kafka consumers
- Predictions written to
telco.churn.predictions
The DAGs in dags/ are copied into .airflow/dags/ during Airflow initialization.
| DAG id | Schedule | Owner | Purpose |
|---|---|---|---|
kafka_batch_consumer_dag |
Hourly | sanila wijesekara | Batch Kafka scoring flow |
kafka_consumer_streaming_dag |
Every minute | sanila wijesekara | Streaming Kafka scoring flow |
The data, training, and inference pipelines are still available as direct make targets, but they are no longer tracked as Airflow DAGs in dags/.
Streaming behavior:
kafka-producer-streamqueueskafka_consumer_streaming_dagafter the stream producer exits.kafka-consumer-continuousqueueskafka_consumer_streaming_dagafter every non-empty inference cycle.kafka-consumerremains the batch consumer entrypoint and maps tokafka_batch_consumer_dag.
Main configuration file: config.yaml
Important settings:
- Training engine: PySpark by default
- Model type: Random Forest
- Data split: 80/20
- Kafka bootstrap server:
localhost:9092 - Airflow home:
.airflow/
The project owner in the DAGs is sanila wijesekara.
- Airflow web UI: http://localhost:8080
- Airflow logs:
.airflow/logs/<dag_id>/<task_id>/ - Airflow scheduler logs:
.airflow/logs/scheduler/ - Kafka logs:
runtime/kafka.log - MLflow UI: http://localhost:5001
- Ensure
AIRFLOW_HOME="$PWD/.airflow" - Ensure
PYTHONPATH="$PWD" - Check scheduler status and DAG logs under
.airflow/logs/
- Ensure Java 17+ is installed
- Verify
KAFKA_HOMEis set when using the native Kafka scripts - Check for port conflicts on
9092and9093 - Review
runtime/kafka.log
If kafka_consumer_streaming_dag does not appear in the UI, make sure the Kafka broker is running before using the streaming producer target. The stream trigger is queued after the producer completes and after each non-empty continuous consumer cycle.
- Run
make train-pipeline - Confirm
artifacts/models/contains the trained model artifacts
- Apache Airflow 2.10+
- PySpark 3.5+
- confluent-kafka
- pandas
- numpy
- scikit-learn
- MLflow
See requirements.txt for the full list.
Sanila Wijesekara