MLOps Pipeline กับ Batch Processing — วิธีสร้าง

MLOps Pipeline คืออะไร

MLOps Pipeline คือ Automated Workflow ที่จัดการทุกขั้นตอนของ Machine Learning Lifecycle อย่างเป็นระบบ ตั้งแต่การดึงข้อมูล (Data Ingestion) การทำ Feature Engineering การ Train Model การ Evaluate ผลลัพธ์ การ Deploy Model ไปจนถึงการ Monitor Model Performance ในระบบ Production
เนื้อหาเกี่ยวข้อง — put call option — ข้อมูลครบถ้วน 2026
Batch Processing Pipeline เป็น Pattern ที่พบบ่อยที่สุดใน MLOps เพราะงาน ML ส่วนใหญ่ไม่ต้องการผลลัพธ์แบบ Real-time เช่น การ Retrain Model ด้วยข้อมูลใหม่ทุกสัปดาห์ การ Generate Recommendations สำหรับผู้ใช้ทุกคนทุกวัน หรือการ Score ลูกค้าเพื่อทำ Marketing Campaign
เนื้อหาเกี่ยวข้อง — อ่านต่อ: Ollama Local LLM RBAC ABAC Policy —
สถาปัตยกรรม Batch MLOps Pipeline
- Data Ingestion: ดึงข้อมูลจาก Database, API, S3 มาเก็บใน Data Lake
- Data Validation: ตรวจสอบคุณภาพข้อมูล Schema, Missing Values, Drift
- Feature Engineering: แปลงข้อมูลดิบเป็น Features สำหรับ Model
- Model Training: Train Model ด้วย Features ใหม่ Log ไปยัง MLflow
- Model Evaluation: เปรียบเทียบ Model ใหม่กับ Model เดิม
- Model Registry: Promote Model ที่ดีกว่าไป Production
- Batch Inference: ใช้ Model ทำ Prediction บนข้อมูลขนาดใหญ่
- Result Storage: เก็บผลลัพธ์ใน Database หรือ Data Warehouse

Docker และ Kubernetes สำหรับ Pipeline
# Dockerfile สำหรับ ML Pipeline Worker
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY src/ ./src/
COPY configs/ ./configs/
ENV PYTHONPATH=/app
ENV MLFLOW_TRACKING_URI=https://mlflow.company.com
CMD ["python", "-m", "src.pipeline.run"]
---
# requirements.txt
apache-airflow==2.8.0
mlflow==2.10.0
scikit-learn==1.4.0
pandas==2.2.0
pyarrow==15.0.0
great-expectations==0.18.0
boto3==1.34.0
---
# kubernetes/ml-pipeline-cronjob.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
name: ml-batch-inference
namespace: ml-platform
spec:
schedule: "0 3 * * *" # ทุกวันตี 3
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 7
failedJobsHistoryLimit: 3
jobTemplate:
spec:
backoffLimit: 2
activeDeadlineSeconds: 7200 # Timeout 2 ชั่วโมง
template:
spec:
restartPolicy: Never
containers:
- name: inference
image: registry.company.com/ml-pipeline:latest
command: ["python", "-m", "src.inference.batch_run"]
resources:
requests:
cpu: "2"
memory: 8Gi
limits:
cpu: "4"
memory: 16Gi
env:
- name: S3_BUCKET
value: "data-lake"
- name: MODEL_NAME
value: "churn-predictor"
- name: MLFLOW_TRACKING_URI
valueFrom:
configMapKeyRef:
name: ml-config
key: mlflow-uri
volumeMounts:
- name: ml-secrets
mountPath: /secrets
readOnly: true
volumes:
- name: ml-secrets
secret:
secretName: ml-pipeline-secrets
Monitoring และ Alerting สำหรับ Batch Pipeline
- Pipeline Health: ติดตาม Success/Failure Rate ของแต่ละ Task, Duration Trend และ SLA Compliance
- Data Quality: ตรวจสอบ Row Count, Schema Changes, Distribution Drift ของ Input Data ทุกรอบ
- Model Performance: ติดตาม Prediction Distribution, F1 Score Trend, Feature Importance Changes
- Resource Usage: CPU, Memory, Disk ของ Pipeline Workers เพื่อ Right-sizing
- Cost Tracking: คำนวณ Cost ต่อ Pipeline Run (Compute + Storage + Network)
MLOps Pipeline คืออะไร
MLOps Pipeline คือ Automated Workflow ที่จัดการทุกขั้นตอนของ Machine Learning ตั้งแต่ Data Ingestion, Feature Engineering, Model Training, Evaluation, Deployment ไปจนถึง Monitoring นำหลักการ DevOps มาใช้กับ ML เพื่อให้ทำซ้ำได้ Scale ได้ และ Maintain ง่าย
แนะนำเพิ่มเติม — iCafeForex
เนื้อหาเกี่ยวข้อง — Linkerd Service Mesh Disaster Recovery Plan





