Design a model evaluation control plane that stores baselines, compares metrics, and…
- User
Design a model evaluation control plane that stores baselines, compares metrics, and gates rollouts for regressions.
- Assistant
Design a model evaluation control plane that stores baselines, compares metrics, and gates rollouts for regressions.
Hmm, the user wants a system design for an evaluation control plane focused on ML model deployments. They mentioned baselines, metric comparison, and rollout gating—essentially a CI/CD but for ML models.
The core requirements are clear: storage for baselines, automated comparison logic, and deployment gates. Need to ensure the design is scalable and integrates with existing ML workflows.
First, I should structure this as a layered system—data layer for baseline/metrics, orchestration for comparison, and control layer for gating. Might need to include core principles to guide the design, like drift detection and statistical rigor.
Key components: baseline storage (with versioning), metric ingestion pipeline, comparison engine (statistical tests), and deployment policies. Should also consider integrations with CI/CD tools and monitoring systems.
Will use a flow diagram to visualize the data and control flow, then break down each component. Need to emphasize automation and guardrails—the system should prevent manual bypasses. Also, operational aspects like alerting and audit logs are critical for production use.
Avoid overcomplicating—keep it modular so teams can adopt parts incrementally. Maybe mention trade-offs like synchronous vs. asynchronous comparisons based on latency needs. I'll design a comprehensive Model Evaluation Control Plane that acts as a centralized system for managing model baselines, automated evaluation, and deployment gating. This system prevents regressions while enabling confident rollouts.
┌─────────────────────────────────────────────────────────────┐
│ CONTROL PLANE LAYER │
├─────────────┬─────────────┬─────────────┬─────────────────┤
│ Baseline │ Evaluation │ Comparison │ Deployment │
│ Manager │ Engine │ Engine │ Gatekeeper │
└─────────────┴─────────────┴─────────────┴─────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────────────────────────────────────────────────┐
│ SHARED STATE & METADATA STORE │
│ (Baseline versions, Metric history, Evaluation results) │
└─────────────────────────────────────────────────────────────┘
Purpose: Versioned storage of approved model baselines per model type/environment.
class Baseline:
id: str # baseline-{model_name}-{version}-{timestamp}
model_id: str # reference to model artifact
metrics: Dict[str, float] # key metrics (accuracy, latency, etc.)
metadata: {
"training_data_snapshot": "hash",
"preprocessing_pipeline": "version",
"approval_status": "approved|rejected|pending",
"approved_by": "team/mechanism",
"valid_time_range": ["start", "end"] # for temporal baselines
}
comparison_thresholds: {
"accuracy_min_delta": 0.01,
"latency_max_increase_pct": 10,
"statistical_test": "t_test|bootstrap"
}
Storage:
Purpose: Execute standardized evaluation pipelines on candidate models.
Evaluation Job Spec:
candidate_model:
artifact_uri: "s3://models/v2/prod/model.pkl"
data_split: "validation|shadow|canary"
evaluation_suite:
- name: "performance_benchmarks"
metrics: ["accuracy", "precision@k", "latency_p99"]
dataset: "validation_set_v1.2"
- name: "business_metrics"
metrics: ["conversion_rate", "revenue_per_user"]
dataset: "recent_7d_prod_traffic"
- name: "drift_detection"
metrics: ["feature_distribution_ks", "prediction_shift"]
reference: "baseline_training_data"
- name: "safety_checks"
metrics: ["bias_metrics", "adversarial_robustness"]
resource_requirements:
cpu: "4"
memory: "16Gi"
timeout: "2h"
Execution:
Purpose: Statistically rigorous comparison between candidate and baseline.
def compare_metrics(candidate_metrics: Dict, baseline_metrics: Dict, thresholds: Dict):
results = {
"overall_pass": True,
"metric_results": {},
"statistical_evidence": {}
}
for metric_name in baseline_metrics:
candidate_val = candidate_metrics[metric_name]
baseline_val = baseline_metrics[metric_name]
threshold = thresholds.get(metric_name, {})
# Direction-aware comparison
if metric_name in ["accuracy", "precision"]: # higher is better
delta = candidate_val - baseline_val
pass_fail = delta >= threshold.get("min_delta", 0)
else: # latency, error_rate (lower is better)
delta = baseline_val - candidate_val
pass_fail = delta >= threshold.get("min_improvement", 0)
# Statistical test if sample data available
if "statistical_test" in threshold:
p_value = run_statistical_test(
candidate_samples,
baseline_samples,
test=threshold["statistical_test"]
)
statistically_significant = p_value < 0.05
results["metric_results"][metric_name] = {
"candidate": candidate_val,
"baseline": baseline_val,
"delta": delta,
"passed": pass_fail,
"p_value": p_value if statistical_test else None
}
if not pass_fail:
results["overall_pass"] = False
return results
Statistical Methods:
Purpose: Enforce deployment policies based on comparison results.
class DeploymentPolicy:
environment: str # staging|canary|production
conditions: [
{
"type": "all_metrics_pass", # all required metrics pass
"required_metrics": ["accuracy", "safety_score"]
},
{
"type": "no_regression", # no metric regresses beyond threshold
"tolerated_regressions": 1, # max allowed
"max_regression_pct": 5
},
{
"type": "statistical_confidence",
"min_confidence_level": 0.95
},
{
"type": "business_metrics_improvement",
"required_improvement": ["revenue_per_user"]
}
]
rollout_strategy: {
"type": "canary|blue_green|rolling",
"steps": [
{"traffic_pct": 5, "duration_minutes": 30},
{"traffic_pct": 20, "duration_minutes": 60},
{"traffic_pct": 100, "duration_minutes": 120}
],
"rollback_triggers": [
"error_rate_increase>10%",
"user_complaint_spike"
]
}
Gate Logic:
┌─────────────────────────────────────────────────────────────┐
│ CLIENTS & INTEGRATIONS │
├─────────────────────────────────────────────────────────────┤
│ CI/CD (GitLab/GitHub Actions) │ ML Platforms (MLflow) │
│ Experiment Tracking (Weights) │ Monitoring (Prometheus)│
└───────────────────────┬─────────────────────────────────────┘
│ API
▼
┌─────────────────────────────────────────────────────────────┐
│ CONTROL PLANE API LAYER │
│ • /baselines/{model}/create │
│ • /evaluations/run │
│ • /comparisons/{evaluation_id}/results │
│ • /deployments/gate-check │
└───────────────────────┬─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ ORCHESTRATION & STATE LAYER │
│ ┌────────────┐ ┌────────────┐ ┌─────────────────────┐ │
│ │ Scheduler │ │ Task │ │ State Machine │ │
│ │ (Airflow) │ │ Queue │ │ (Deployment flow) │ │
│ └────────────┘ └────────────┘ └─────────────────────┘ │
└───────────────────────┬─────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ PERSISTENCE LAYER │
├─────────────────────────────────────────────────────────────┤
│ PostgreSQL: Metadata, baselines, policies, audit logs │
│ Redis: Cache, locks, short-term state │
│ S3/MinIO: Evaluation artifacts, model snapshots │
└─────────────────────────────────────────────────────────────┘
1. Developer merges PR → CI triggers model training
2. Training completes → New model registered in ML registry
3. CI calls Control Plane API:
POST /evaluations/run
{
"model_id": "prod-recommender-v3",
"baseline_id": "baseline-prod-recommender-v2-20240101",
"evaluation_suite": "production_canary",
"data_split": "recent_1h_traffic_5%_sample"
}
4. Scheduler creates evaluation job → Runs on Kubernetes
5. Evaluation completes → Results stored:
{
"evaluation_id": "eval-123",
"metrics": {
"accuracy": 0.892, // baseline: 0.889
"latency_p99": 210ms, // baseline: 195ms
"revenue_per_user": 0.0% change
},
"comparison": {
"accuracy": {"delta": +0.003, "passed": true, "p_value": 0.12},
"latency": {"delta": +15ms, "passed": false, "p_value": 0.01},
"revenue": {"passed": true}
}
}
6. CI calls gate-check:
POST /deployments/gate-check
{
"model_id": "prod-recommender-v3",
"environment": "canary",
"evaluation_id": "eval-123"
}
7. Gatekeeper evaluates against policy:
❌ Latency regression >5% threshold (-8% increase)
✅ All other metrics pass
→ **GATE FAILED**
8. System:
- Stores gate decision with reason
- Creates GitHub status check: "🔴 Evaluation Failed"
- Sends Slack/Teams alert with details
- Blocks deployment
- Recommends: "Investigate latency regression, consider optimization"
9. Developer fixes issue → Re-runs evaluation → All gates pass
→ Gate approves → Canary deployment begins
→ Monitoring continues comparing to original baseline
BASELINE_SELECTORS = {
"latest_approved": "Most recent approved baseline",
"performance_optimized": "Best metric in last 30 days",
"rollback_target": "Previous stable version (n-2)",
"time_window": "Baseline from same week/day last year",
"traffic_based": "Baseline from similar traffic segment"
}
# Instead of fixed canary percentages
class BanditRollout:
def allocate_traffic(self, model_variants):
# Thompson Sampling or UCB1
# Adjusts traffic based on real-time metric feedback
# Success = metrics within thresholds + business KPIs
Continuous Monitoring → Detects feature drift (KS-test)
↓
Automatically triggers new evaluation against original baseline
↓
If regression detected → Alert + optional auto-rollback
templates:
production_critical:
required_metrics: ["accuracy", "recall", "latency_p99"]
statistical_test: "bootstrap"
max_regression_pct: 2
canary_duration: "2h"
rapid_experiment:
required_metrics: ["primary_business_metric"]
statistical_test: null # no stat test needed
max_regression_pct: 10
canary_duration: "15m"
safety_critical:
required_metrics: ["fairness_score", "safety_score"]
statistical_test: "permutation_test"
max_regression_pct: 0 # no regression allowed
requires_human_approval: true
Centralized catalog with:
Severity 1 (gate failure): → PagerDuty + Slack #model-alerts
Severity 2 (regression): → Team Slack channel + daily digest
Severity 3 (drift detected): → Weekly report
EVERY decision must log:
| Component | Option A (K8s Native) | Option B (Managed) | Option C (Serverless) |
|---|---|---|---|
| Orchestration | Airflow/Kubeflow Pipelines | AWS Step Functions | Temporal.io |
| Storage | PostgreSQL + S3 | AWS RDS + S3 | Supabase + Cloud Storage |
| Queue | RabbitMQ/Kafka | AWS SQS | Redis Streams |
| API | FastAPI + Gunicorn | AWS API Gateway + Lambda | Vercel/Cloudflare Workers |
| Scheduler | CronJob + Config | AWS EventBridge | GitHub Actions |
# models/my-recommender/evaluation-policy.yaml
api_version: eval-control-plane/v1
kind: DeploymentPolicy
metadata:
name: recommender-policy
model: "my-recommender"
environment: "production"
spec:
baseline_selector:
strategy: "latest_approved"
min_approval_time: "24h"
max_age_days: 30
required_evaluations:
- name: "offline_validation"
dataset: "validation_set_v2"
metrics:
- name: "roc_auc"
min_improvement: 0.001
statistical_test: "bootstrap"
- name: "log_loss"
max_regression_pct: 5
- name: "online_shadow"
duration: "4h"
traffic_split: 5% # shadow 5% of traffic
metrics:
- name: "business_kpi"
min_improvement: 0.5%
deployment_gates:
- type: "all_evaluations_pass"
- type: "no_critical_regression"
critical_metrics: ["safety_score"]
- type: "statistical_confidence"
min_confidence: 0.95
rollout:
strategy: "progressive"
canary_steps:
- traffic: 5%
duration: "1h"
auto_rollback_triggers: ["error_rate>2%"]
- traffic: 20%
duration: "2h"
- traffic: 100%
Phase 1 (Weeks 1-2): Core baseline storage + static comparison Phase 2 (Weeks 3-4): Integration with CI + simple gating Phase 3 (Weeks 5-6): Statistical tests + automated evaluation Phase 4 (Weeks 7-8): Canary integration + monitoring hooks Phase 5 (Weeks 9-10): Advanced features (bandit, drift detection)
This design provides a production-grade, auditable, and statistically sound system that prevents regressions while enabling safe, data-driven deployments. The key is treating baseline management as a first-class concern with proper versioning and making comparison decisions explicit and policy-driven.