Skip to content
About Me
----

Model Serving & Real-Time Drift Detection: KServe, Triton & Evidently AI

Architect Key Takeaways

Production guide to serving machine learning models at scale on Kubernetes with KServe and NVIDIA Triton, implementing canary rollouts, and detecting data drift with Evidently AI.

Model Serving & Real-Time Drift Detection: KServe, Triton & Evidently AI

Section titled β€œModel Serving & Real-Time Drift Detection: KServe, Triton & Evidently AI”

Deploying a model artifact into production is where engineering challenges truly begin. A production ML serving system must solve:

  • Low-Latency Inference: Processing requests in single-digit milliseconds under high concurrency.
  • Dynamic Autoscaling: Scaling GPU/CPU pods from zero during idle periods to hundreds during traffic spikes.
  • Canary & Shadow Routing: Testing new model versions against live traffic without risking revenue or user experience.
  • Continuous Drift Detection: Detecting statistical divergence in input data (Data Drift) or prediction accuracy (Concept Drift) before catastrophic failures occur.

Standard Python web frameworks like Flask or FastAPI are not designed for high-concurrency model serving: they suffer from Python’s Global Interpreter Lock (GIL) and lack dynamic batching.

KServe (a CNCF project built on Knative and Istio) and NVIDIA Triton Inference Server provide the gold standard for enterprise serving:

[ Client Applications ]
β”‚
β–Ό (HTTPS / gRPC)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Istio Ingress Gateway / Envoy VirtualService β”‚
β”‚ β”œβ”€ 90% Traffic: Production Model v1.0 β”‚
β”‚ └─ 10% Traffic: Canary Model v2.0 (Testing) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ KServe InferenceService (Kubernetes Pod) β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ NVIDIA Triton Inference Engine (C++ Multi-threaded)β”‚ β”‚
β”‚ β”‚ β€’ Dynamic Request Batching (1ms window) β”‚ β”‚
β”‚ β”‚ β€’ Multi-Framework Support (PyTorch, ONNX, TensorRT)β”‚ β”‚
β”‚ β”‚ β€’ Shared GPU Memory Concurrency β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

1.1 Declarative KServe InferenceService with Canary Traffic Splitting

Section titled β€œ1.1 Declarative KServe InferenceService with Canary Traffic Splitting”
apiVersion: "serving.kserve.io/v1beta1"
kind: "InferenceService"
metadata:
name: "fraud-detector"
namespace: "mlops"
spec:
predictor:
# 1. Primary Production Model (90% Traffic)
model:
modelFormat:
name: onnx
storageUri: "s3://enterprise-model-registry/fraud-detector/v1.4/"
resources:
requests:
cpu: "2"
memory: "4Gi"
limits:
cpu: "4"
memory: "8Gi"
minReplicas: 2
maxReplicas: 20
scaleMetric: concurrency
scaleTarget: 10
# 2. Canary Candidate Model (10% Traffic)
canaryTrafficPercent: 10
canary:
model:
modelFormat:
name: onnx
storageUri: "s3://enterprise-model-registry/fraud-detector/v2.0-rc1/"
resources:
requests:
cpu: "2"
memory: "4Gi"

2. Understanding Model Drift: Data Drift vs Concept Drift

Section titled β€œ2. Understanding Model Drift: Data Drift vs Concept Drift”

Unlike traditional software bugs that throw 500 Internal Server Errors, a degraded ML model continues to return clean 200 OK responses with high confidenceβ€”while making completely incorrect business predictions.

+--------------------------------------------------------------------------+
| 1. DATA DRIFT (Covariate Shift) |
| β€’ The statistical distribution of input features changes: P(X) changes. |
| β€’ Example: An e-commerce fraud model trained on domestic transactions |
| suddenly receives 50% international transactions with unfamiliar IPs. |
+--------------------------------------------------------------------------+
+--------------------------------------------------------------------------+
| 2. CONCEPT DRIFT |
| β€’ The mathematical relationship between inputs and outputs changes: |
| P(Y|X) changes. |
| β€’ Example: Consumer purchasing behaviors change overnight during an |
| economic recession or global pandemic. Inputs look normal, but |
| prediction relationships are invalid. |
+--------------------------------------------------------------------------+

3. Real-Time Drift Detection with Evidently AI & Prometheus

Section titled β€œ3. Real-Time Drift Detection with Evidently AI & Prometheus”

To catch drift before it impacts users, production pipelines stream live inference payloads to a drift evaluation service:

import pandas as pd
from evidently.report import Report
from evidently.metric_preset import DataDriftPreset
from prometheus_client import Gauge, start_http_server
# Prometheus metrics for SRE Alertmanager integration
DRIFT_SCORE_GAUGE = Gauge(
"model_feature_drift_score",
"Kolmogorov-Smirnov Drift Score for Feature",
["feature_name", "model_version"]
)
def evaluate_production_drift(reference_df: pd.DataFrame, live_batch_df: pd.DataFrame):
"""Calculates statistical drift using Kolmogorov-Smirnov (KS) test."""
report = Report(metrics=[DataDriftPreset()])
report.run(reference_data=reference_df, current_data=live_batch_df)
results = report.as_dict()
metrics = results["metrics"][0]["result"]
dataset_drift = metrics["dataset_drift"]
# Export feature-level drift scores to Prometheus
for feature_name, details in metrics["drift_by_columns"].items():
drift_p_value = details["drift_score"]
DRIFT_SCORE_GAUGE.labels(
feature_name=feature_name,
model_version="v1.4"
).set(drift_p_value)
# Statistical significance threshold (p-value < 0.05 indicates drift)
if details["drift_detected"]:
print(f"CRITICAL DRIFT: Feature '{feature_name}' drifted! p-value: {drift_p_value:.4f}")
if dataset_drift:
print("ACTION REQUIRED: More than 50% of features have drifted. Triggering Continuous Training (CT) pipeline.")
trigger_kubeflow_retraining_dag()

4. Automated Continuous Retraining Trigger via Prometheus Alert

Section titled β€œ4. Automated Continuous Retraining Trigger via Prometheus Alert”

In a mature MLOps platform, drift alerts in Prometheus automatically invoke the Kubeflow retraining pipeline:

# Prometheus Alerting Rule for Model Drift
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: ml-model-drift-alerts
namespace: mlops
spec:
groups:
- name: mlops.drift
rules:
- alert: SignificantFeatureDriftDetected
expr: model_feature_drift_score{model_version="v1.4"} < 0.05
for: 15m
labels:
severity: warning
team: data-platform
annotations:
summary: "Statistical data drift detected on feature {{ $labels.feature_name }}"
description: "Feature has diverged from training baseline for >15 minutes. Retraining required."
runbook_url: "https://devsecopsguru.in/mlops/mlops-foundations-lifecycle/"

  1. Enable Dynamic Batching in Triton: Configure max_queue_delay_microseconds: 2000 (2ms) in Triton. This bundles incoming concurrent requests into a single tensor batch, multiplying GPU inference throughput by up to 8x with negligible latency impact.
  2. Implement Shadow Deployments (Dark Traffic): Before shifting live canary traffic to a new model, mirror 100% of production requests to the candidate model asynchronously (mirror: true in Istio). Verify latency and output sanity without returning results to users.
  3. Persist Inference Logs Asynchronously: Never write inference request/response payloads synchronously in the critical path. Push raw payloads to an AWS Kinesis or Kafka stream for asynchronous drift and compliance processing.