ONLINE ML · PRODUCTION ARCHITECTURE · CONTINUOUS EVIDENCE

คำว่า Online
ไม่ได้หมายถึงสิ่งเดียว

บางระบบทำนายทันทีแต่ฝึกเป็นรอบ บางระบบอัปเดต feature ต่อเนื่อง และมีเพียงบางระบบที่แก้น้ำหนักโมเดลทีละ event ถ้าไม่แยกสามความหมายนี้ เราจะเลือก architecture ผิดตั้งแต่ต้น

01 · PREDICTmilliseconds
02 · FEATUREseconds–minutes
03 · LEARNevent-by-event
04 · VERIFYlabels arrive later

THREE PRODUCTION PATTERNS

ออนไลน์ตรงไหน ต้องบอกให้ชัด

ทั้งสามแบบอาจอยู่ในระบบเดียว แต่มี state, latency, failure mode และวิธีประเมินต่างกัน

01

Online Inference

โมเดลคงที่ชั่วคราว แต่ตอบทันที

ใช้แพร่หลายที่สุด และมักถูกเรียกว่า online ML แม้ไม่ได้เรียนรู้ทุก request
Request
Online features
Model server
Prediction + log

สิ่งที่ต้องเร็ว

Feature lookup, preprocessing parity, model execution and response serialization.

เครื่องมือ

Feast/Redis · KServe/Triton/BentoML · XGBoost/ONNX/PyTorch.

ตัวอย่าง

ตรวจ fraud, ranking สินค้า, credit scoring และ image inference

request → online_features(entity_id, event_time) → model.predict(feature_vector) → log(prediction_id, feature_version, model_version)
02

Online Feature Computation

Feature เปลี่ยนต่อเนื่อง โมเดลอาจยังฝึกเป็นรอบ

หัวใจของ fraud และ recommendation จำนวนมาก ความสดมักมาจาก feature ไม่ใช่ weight ใหม่
Kafka / events
Flink / SQL / IVM
Feature state
Inference

State ที่รักษา

Count, sum, mean, variance, distinct entities, recency, histogram and co-occurrence.

โจทย์เวลา

Event time, processing time, late events, watermarks, sliding windows and expiration.

ตัวอย่าง

transaction velocity 5 นาที, spend 7 วัน, CTR 24 ชั่วโมง

new_event(entity=104, amount=2500) → count_5m += 1 → sum_7d += 2500 → expire old contributions → serve revised features
03

True Online Learning

ทำนายก่อน แล้วอัปเดตโมเดลเมื่อ label มาถึง

ใช้เมื่อ environment เปลี่ยนเร็ว feedback เชื่อถือได้ และควบคุมความเสี่ยงจาก update ได้
xₜ
predict_one
delayed yₜ
learn_one + checkpoint

โมเดลที่เหมาะ

Online linear/logistic models, Naive Bayes, Hoeffding trees, bandits and incremental anomaly detection.

เครื่องมือ

River · Vowpal Wabbit · sufficient-statistic updates.

ความเสี่ยง

Poisoning, feedback loops, catastrophic forgetting, label delay and rollback.

ŷₜ = predict_one(xₜ) → log evidence → wait for verified yₜ → metric.update(yₜ, ŷₜ) → learn_one(xₜ, yₜ) → checkpoint

DECISION TABLE

เลือกจาก latency และการเปลี่ยนแปลง

การอัปเดตโมเดลทุก event ไม่ได้ก้าวหน้ากว่าเสมอ หลายระบบควรหยุดที่ Pattern 1 หรือ 2

QuestionOnline inferenceOnline featuresTrue online learning
สิ่งที่เปลี่ยนทันทีPredictionFeature stateModel parameters
ต้องมี label ทันทีไหมNoNoไม่ แต่ต้องจับคู่ย้อนหลังได้
เหมาะเมื่อต้องตอบเร็วพฤติกรรมล่าสุดสำคัญแนวคิดเปลี่ยนเร็ว
หลักฐานLatency, availabilityFreshness, skew, driftProgressive loss, regret, stability
RollbackModel versionFeature state/versionCheckpoint + replay log

SCENARIOS

ผลิตภัณฑ์ต่างกัน ต้องการ online คนละชนิด

เลือกกรณีเพื่อดู prediction latency, feature freshness และ label delay

Payment Fraud

ตอบก่อนอนุมัติธุรกรรม feature velocity ต้องสด แต่ chargeback label อาจมาหลายวัน จึงไม่ควรเรียนจากทุก decline โดยตรง

<100 msinference
1–10 sfeatures
dayslabel delay

Recommendation

Popularity และ session context เปลี่ยนเร็ว ส่วน embedding ใหญ่ refresh เป็นรอบ และ bandit ใช้กับ exploration

<50 msranking
secondssession
minutes+feedback

Predictive Maintenance

sensor feature ไหลต่อเนื่อง แต่ failure พบไม่บ่อย จึงมัก retrain แบบ micro-batch หลังตรวจ drift

secondswindows
rarelabels
scheduledretraining

DRIFT & DELAYED TRUTH

Prediction เกิดวันนี้ ความจริงอาจมาสัปดาห์หน้า

ต้องเก็บ prediction_id, event time, feature version และ model version เพื่อเชื่อม label กลับไปยังหลักฐานเดิม

แยกสัญญาณให้ถูก

Feature drift: P(X) · Label drift: P(Y) · Concept drift: P(Y|X) · Prediction drift: P(Ŷ) · Performance drift: loss after labels arrive.

prediction_log(prediction_id, entity_id, event_time, feature_version, model_version, predicted_label, probability)
verified_labels(prediction_id, label_time, actual_label)
evaluate by prediction event window—not only label arrival time

PRACTICAL WARIN.ME STACK

เล็กพอให้เรียน จริงพอให้เห็น production boundary

ใช้ ClickHouse เป็น evidence/state engine แล้วต่อ River หรือ Vowpal Wabbit เฉพาะ true online mode

Events
ClickHouse state
Inference API
Drift + labels
River/VW or retrain