Phase 5: MLOps & Production

A/B Testing & Shadow Deployments

Advanced ~2 min read
Think of it this way A friendly analogy. Read this if the technical version feels dense. Show Hide

You’ve probably helped bake cookies, right? Or maybe you have a favorite family recipe. Imagine your parents have a super popular cookie recipe, everyone loves them. But then, they come up with a new idea – maybe adding chocolate chips and sprinkles, or using a different kind of flour to make them extra chewy. They think this new recipe might be even better! But how do they know for sure without ruining everyone's dessert or wasting a lot of ingredients?

One way to find out is like having a "taste-off" party. They could make two batches: one with the old, reliable recipe (let's call it Recipe A), and one with the new, exciting recipe (Recipe B). Then, they invite two groups of friends. One group only gets cookies from Recipe A, and the other group only gets cookies from Recipe B. Nobody knows there's a test! After the party, they’d look at which plate was emptier, or which group raved more about their cookies. If Recipe B's plate was licked clean and everyone asked for the recipe, they’d know it’s a winner! This "taste-off" helps them see which recipe performs better with real people, not just by tasting it themselves.

But what if they're not ready for a big taste-off, or they're worried the new recipe might turn out really weird or even burn the kitchen down? This is where a "secret taste test" comes in. They would still bake the old, reliable Recipe A to serve to all their guests, just like always. But at the same time, they would secretly bake a small batch of the new Recipe B in the kitchen. They wouldn't serve Recipe B to anyone. Instead, they'd watch it closely – does it smell right? Does it bake evenly? Do they like the taste? If Recipe B looks and smells good, and they think it tastes promising without causing any trouble, then maybe it's safe enough to try a "taste-off" later. If it melts into a puddle, they just throw it out, and nobody's dessert was ruined.

So, whether it's giving two different groups of friends cookies to see which they like best, or secretly baking a new recipe to check if it's safe before anyone tastes it, these ideas are super useful. This means you can try out new things, like a new way to organize a website or a different way a computer program gives suggestions, knowing you're finding the best option for everyone without breaking anything for the people using it right now. You get to learn and improve constantly, making sure everyone gets the best "cookies" possible!

A/B testing, in the context of model serving, involves directing different subsets of live production traffic to distinct model versions to compare their real-world performance. The primary goal is to validate which model (e.g., a baseline Model A versus a new Model B) performs better against specific business metrics, such as conversion rates, user engagement, or fraud detection accuracy, rather than solely relying on offline ML metrics. This requires a robust traffic routing mechanism, typically at the API gateway or service mesh level, and careful statistical analysis to determine if observed differences are significant and warrant a full rollout of the winning model.

Shadow deployments, often called dark launches, provide a low-risk method for validating a new model's operational stability and predictive behavior under live traffic conditions without impacting end-users. With a shadow deployment, all or a percentage of incoming production requests are duplicated and sent to both the currently active model and the new 'shadow' model. The key difference is that only the active model's predictions are returned to the user; the shadow model's predictions are discarded or logged for comparison. This allows MLOps teams to monitor the shadow model's latency, error rates, resource consumption, and the quality of its predictions (e.g., comparing its outputs to the live model's outputs for significant divergence) before it ever serves a user.

Practically, shadow deployments often precede A/B tests. First, you'd deploy a new model in shadow mode to ensure it's stable and performs as expected operationally under real load. Once validated, you might then move to an A/B test, gradually exposing a small percentage of users to the new model to measure its impact on business-critical metrics. Tools like service meshes (e.g., Istio, Linkerd) or cloud-native load balancers are instrumental in managing the complex traffic routing and mirroring required for these advanced deployment strategies.

Key Takeaways

  • A/B testing compares live model performance using split production traffic, focusing on business metrics to determine user impact.
  • Shadow deployments validate new models under live traffic without impacting users, primarily for operational stability and prediction health checks.
  • Shadow deployments often precede A/B tests, de-risking new model rollouts by verifying operational readiness first.
  • Both strategies require robust traffic management (e.g., service mesh) and comprehensive monitoring.
  • The ultimate goal is to safely and strategically deploy models that drive better business outcomes.

Code Example

yaml
apiVersion: networking.k8s.io/v1beta1
kind: VirtualService
metadata:
  name: ml-inference-service
spec:
  hosts:
  - "ml-api.example.com"
  gateways:
  - ml-gateway
  http:
  - route:
    - destination:
        host: ml-model-v1 # Baseline model (A)
        port:
          number: 80
      weight: 90
    - destination:
        host: ml-model-v2 # Challenger model (B)
        port:
          number: 80
      weight: 10

How this code works

This YAML configures a VirtualService to manage how user requests are routed to different versions of an ML model, enabling A/B testing or gradual rollouts. Specifically, it directs traffic to either ml-model-v1 (the baseline model) or ml-model-v2 (the challenger). This allows engineers to compare the performance of a new model (v2) with the existing one (v1) using real user traffic, without fully exposing v2 to everyone immediately. The service exposed via ml-api.example.com acts as the single entry point for all inference requests, abstracting away the underlying model versions.

Inside the spec, the hosts entry ml-api.example.com defines the public-facing URL for the ML service, while gateways links it to the cluster's ingress. The core routing logic is under http, where a list of route objects specifies traffic distribution. Each destination points to an internal Kubernetes service (like ml-model-v1 or ml-model-v2) which represents a specific deployment of a model version, usually accessed on port 80. The crucial part is weight: ml-model-v1 receives 90% of requests, and ml-model-v2 gets 10%. A common pitfall is forgetting that these weight values for all destinations within a single http block must always sum to 100 to ensure all traffic is accounted for, otherwise some requests might not be routed at all.