How ertis-research/kafka-ml works
Purpose and Entry Points
Kafka-ML is a Kubernetes-based ML pipeline platform for defining, training, deploying, and monitoring TensorFlow/Keras and PyTorch models over Apache Kafka streams, including distributed, incremental, semi-supervised, and federated TensorFlow training. Users enter through the Angular UI; workloads run as containerized Kubernetes services.
• frontend/src/main.ts
• backend/manage.py
• kustomize/local/kustomization.yaml
UI and API Control Plane
The Angular frontend manages models, configurations, deployments, inference endpoints, IoT devices, results, and visualization. It calls the Django backend REST API and consumes visualization updates through WebSockets.
• frontend/src/app/app-routing.module.ts
• frontend/src/app/services/visualization-ws.service.ts
• backend/automl/urls.py
• backend/automl/websockets.py
Backend Orchestration and Persistent Domain
Django is the system’s control plane: it persists ML/domain entities, exposes APIs, converts configuration and deployment requests into Kubernetes job/deployment manifests, and records training/inference state. ASGI supports HTTP plus real-time updates; nginx is packaged as a separate backend-facing proxy.
• backend/autoweb/settings.py
• backend/automl/models.py
• backend/automl/views/deployments.py
• backend/automl/views/utils/job_manifest_generator.py
Stream Ingestion and Control Signaling
Apache Kafka is the primary data boundary: external producers write raw or Avro training/inference records keyed by deployment/topic configuration; workers consume them and publish model outputs, metrics, and control events. Datasource sink libraries are the producer-facing integration boundary. A control logger monitors Kafka-side lifecycle/control messages.
• datasources/sink.py
• datasources/raw_sink.py
• datasources/avro_sink.py
• kafka_control_logger/logger.py
ML Code Execution and Training Workers
User-provided model code is executed outside the backend in dedicated TensorFlow or PyTorch executor services, keeping framework/runtime dependencies and arbitrary ML code isolated from the control plane. Training containers consume Kafka datasets, execute single or distributed training, and emit trained artifacts/results. TensorFlow contains the richer training modes: classic, edge/cloud distributed, incremental, semi-supervised, and blockchain/federated-related paths.
• mlcode_executor/tfexecutor/app.py
• mlcode_executor/pthexecutor/app.py
• model_training/tensorflow/mainTraining.py
• model_training/pytorch/training.py
Inference and Visualization Flow
A trained model is deployed as a framework-specific inference service. It consumes input records from configured Kafka topics, emits predictions to output topics, and supports chained distributed-model inference through upper-model topics and confidence thresholds. The UI visualization layer subscribes to backend WebSocket output for classification or regression displays.
• model_inference/tensorflow/inference.py
• model_inference/pytorch/inference.py
• backend/automl/views/inferences.py
• frontend/src/app/visualization/visualization.component.ts
Federated Learning Subsystem
Federated learning is a separate TensorFlow-only deployment slice. A federated backend and Kafka control loggers coordinate device data/model control events; federated training aggregates client model updates rather than centralizing raw data. It has its own Kustomize base and master/GPU overlays, distinct from the standard pipeline.
• federated-module/federated_backend/automl/views.py
• federated-module/federated_model_training/tensorflow/federated_mainTraining.py
• federated-module/federated_model_training/tensorflow/FederatedKafkaMLAggregationSink.py
• federated-module/kustomize/base/kustomization.yaml
Runtime and Infrastructure Boundaries
Services are Dockerized Python (Django, TensorFlow, PyTorch, Kafka clients) and Angular/Node-built frontend artifacts, deployed through Kustomize overlays. Kubernetes is both the workload scheduler and backend orchestration target; Kafka is externally addressable/configured through manifests. CPU is default, while GPU-specific overlays and resource configuration support NVIDIA/GPU-sharing deployments.
• kustomize/base/resources/backend-deployment.yaml
• kustomize/base/resources/tf-executor-deployment.yaml
• kustomize/base/resources/kafkaml-configmap.yaml
• kustomize/master-gpu/kustomization.yaml
Main entry points: kustomization.yaml Kubernetes + Kustomize · manage.py Django API / ASGI · main.ts Angular UI · visualization-ws.service.ts Visualization WebSocket
Components 20
Control Plane
- Angular UI · Manages models, deployments, devices, results, and visualization.
frontend/src/main.ts - UI routes
frontend/src/app/app-routing.module.ts - Visualization WebSocket
frontend/src/app/services/visualization-ws.service.ts - Django API / ASGI · HTTP and real-time control-plane entry point.
backend/manage.py - Domain state · Persists configurations, deployments, training, and inference state.
backend/automl/models.py - Deployment orchestrator · Turns deployment requests into Kubernetes workloads.
backend/automl/views/deployments.py - Job manifest generator
backend/automl/views/utils/job_manifest_generator.py - Inference API
backend/automl/views/inferences.py
Streaming ML
- Apache Kafka · Carries records, predictions, metrics, and control events.
- Datasource sinks · External raw and Avro producer integration boundary.
datasources/sink.py - Kafka control logger
kafka_control_logger/logger.py - TensorFlow executor · Isolates user TensorFlow/Keras code from the backend.
mlcode_executor/tfexecutor/app.py - PyTorch executor · Isolates user PyTorch code from the backend.
mlcode_executor/pthexecutor/app.py - TensorFlow training · Runs classic, distributed, incremental, semi-supervised, and related modes.
model_training/tensorflow/mainTraining.py - PyTorch training
model_training/pytorch/training.py - TensorFlow inference · Consumes input topics and publishes predictions.
model_inference/tensorflow/inference.py - PyTorch inference
model_inference/pytorch/inference.py
Federated Learning
Separate TensorFlow deployment slice.
- Federated backend · Coordinates federated device and model control events.
federated-module/federated_backend/automl/views.py - Federated TF training · Aggregates client model updates without centralizing raw data.
federated-module/federated_model_training/tensorflow/federated_mainTraining.py
Runtime Platform
- Kubernetes + Kustomize · Schedules containerized services with CPU and GPU overlays.
kustomize/local/kustomization.yaml
Connections 25
- Angular UI → UI routes: navigates
- Angular UI → Django API / ASGI: REST requests
- Angular UI → Visualization WebSocket: visualizes through
- Visualization WebSocket → Django API / ASGI: WebSocket updates
- Django API / ASGI → Domain state: reads and records state
- Django API / ASGI → Deployment orchestrator: deployment requests
- Django API / ASGI → Inference API: inference state
- Deployment orchestrator → Job manifest generator: generates
- Job manifest generator → Kubernetes + Kustomize: applies workloads
- Kubernetes + Kustomize → TensorFlow executor: runs
- Kubernetes + Kustomize → PyTorch executor: runs
- Kubernetes + Kustomize → TensorFlow training: runs
- Kubernetes + Kustomize → PyTorch training: runs
- Kubernetes + Kustomize → TensorFlow inference: runs
- Kubernetes + Kustomize → PyTorch inference: runs
- Datasource sinks → Apache Kafka: publishes records
- TensorFlow training → Apache Kafka: consumes data; publishes results
- PyTorch training → Apache Kafka: consumes data; publishes results
- TensorFlow inference → Apache Kafka: consumes inputs; publishes predictions
- PyTorch inference → Apache Kafka: consumes inputs; publishes predictions
- Kafka control logger → Apache Kafka: monitors control events
- Federated backend → Apache Kafka: coordinates control events
- Federated TF training → Apache Kafka: aggregates client updates
- Kubernetes + Kustomize → Federated backend: deploys
- Kubernetes + Kustomize → Federated TF training: deploys