In this lesson, you will learn how to mirror live production traffic to a staging environment to validate new features without exposing your real-world users to potential bugs.
What is Shadow Traffic?
Shadow traffic—often called "traffic mirroring"—is a deployment pattern where your production load balancer or service mesh duplicates incoming requests and sends them to both your stable production service and a "shadow" version of your new service. The critical difference from a canary or A/B test is that the responses from the shadow service are discarded or logged for analysis; the end user only ever receives the response from the production service.
This is the ultimate "risk-free" test because even if your new code crashes or processes data incorrectly, your actual users remain completely unaffected.
How it Works in Kubernetes
While simple Ingress controllers often lack advanced mirroring, service meshes like Istio excel here. You configure a VirtualService to split traffic, but instead of routing a percentage of users to the new version, you instruct the mesh to "mirror" 100% of the traffic.
Here is a conceptual look at how you might define a mirrored route in an Istio VirtualService:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
spec:
hosts:
- my-app
http:
- route:
- destination:
host: my-app-prod
subset: v1
weight: 100
mirror:
host: my-app-shadow
subset: v2
In this setup, the v1 service handles the real users, while the v2 service receives an identical copy of every incoming request. Because v2 is just a shadow, you can observe logs, performance metrics, and error rates to ensure the new code handles the actual production load perfectly before you ever officially promote it.
Why Use It?
- Zero User Impact: Since the user never sees the shadow response, you can test breaking changes safely.
- Realistic Load: Unlike synthetic testing, you are testing against actual user request patterns, headers, and payloads.
- Validation: It is perfect for verifying database performance and downstream service interactions without the risk of "polluting" your live data.
Key Takeaway: Shadow traffic allows you to validate new code against live production data in real-time, ensuring stability by discarding the output while keeping the insights.