MLOps A/B testing isn’t just about comparing model performance; it’s fundamentally about comparing the impact of different models on user behavior and business metrics in a live, production environment.

Let’s see this in action. Imagine we have a recommendation engine. We’ve trained model-v1 and model-v2. We want to see which one drives more clicks.

Here’s a simplified snapshot of traffic allocation and logging:

// Request to the inference service
{
  "user_id": "user123",
  "context": {"page": "homepage"},
  "model_variant": "v2" // This is decided by the A/B testing framework
}

// Inference response
{
  "recommendations": [
    {"item_id": "itemA", "score": 0.95},
    {"item_id": "itemB", "score": 0.88}
  ],
  "model_used": "model-v2"
}

// User interaction logged downstream (e.g., click)
{
  "user_id": "user123",
  "event_type": "recommendation_click",
  "item_id": "itemA",
  "timestamp": "2023-10-27T10:00:00Z",
  "model_variant_served": "v2" // Crucial for attribution
}

The A/B testing framework intercepts incoming requests. Based on a predefined traffic split (e.g., 50/50, 90/10) and potentially user bucketing logic (e.g., sticky sessions for a user), it assigns each request to a specific model variant (v1 or v2). The inference service then uses the assigned model. Crucially, the response (or an intermediary log) must carry this assignment information so that downstream events (clicks, conversions, etc.) can be correctly attributed to the model variant that generated the recommendations.

The core problem A/B testing solves in MLOps is the uncertainty about a new model’s real-world effectiveness. Offline metrics (like AUC, RMSE) are essential but don’t always translate to online business outcomes. A model might have a slightly lower AUC but be faster, less prone to serving stale data, or simply recommend items users are more likely to engage with, leading to higher conversion rates or revenue. A/B testing provides a statistically sound method to measure this direct impact before a full rollout.

Internally, an A/B testing system for models typically involves several components:

  1. Traffic Splitting/Bucketing: Logic to divide incoming traffic. This can be random, based on user IDs (e.g., hash(user_id) % 100 < 50 for 50%), or session-based.
  2. Experiment Configuration: A system to define experiments, variants, traffic allocation percentages, and the metrics to track.
  3. Inference Service Integration: The ability to direct requests to different model deployments (e.g., separate Kubernetes deployments, different model versions within a single serving framework like Triton Inference Server).
  4. Logging & Attribution: A robust mechanism to log which variant served which request and, critically, to link subsequent user actions back to that specific variant. This often involves enriching request/response logs with experiment metadata and ensuring downstream event tracking systems capture this model_variant_served field.
  5. Analysis & Reporting: Tools to aggregate logged data, perform statistical significance tests (t-tests, chi-squared tests), and visualize results (e.g., conversion rate difference, revenue per user).

The levers you control are primarily the variants you deploy and the traffic split. You can also influence the duration of the experiment and the metrics you choose to monitor. For instance, if you’re testing a new click-through rate (CTR) model, you’d track clicks on recommended items. If it’s a revenue optimization model, you’d track the revenue generated from those recommendations.

A subtle but critical aspect is how you handle "cold start" users or items. If your new model has a different approach to handling unseen entities, this can significantly impact early experiment results. You need to ensure your logging and attribution correctly capture whether a user or item was "new" to the system during the experiment, as this can be a confounding factor. For example, if model-v2 is better at recommending popular items, and your experiment starts when a new popular item is released, v2 might appear to perform better simply due to this external factor, not its inherent recommendation quality for established users.

The next step after successfully comparing models via A/B testing is often to explore multi-armed bandit strategies for dynamically allocating traffic based on early performance signals.

Want structured learning?

Take the full MLOps & AI DevOps course →