Video in progress
How do you use traffic mirroring (shadow traffic) to test a rewritten service in prod with real traffic but without affecting users?
A copy of the requests is also sent to the new version, and its response is discarded: the user gets only the old version's response. Responses and latency are compared. The biggest risk is side effects: the shadow version must not write to the prod DB, send events or charge money.
📖 Answer
When it's useful: you rewrote the pricing module from the monolith as a new service. The unit tests are green, but there are thousands of real carts and discount combinations. Shadow traffic tests the new code safely on real input for a week.
How it's done:
- At the mesh or proxy level:
mirrorandmirrorPercentagein an IstioVirtualService, themirrordirective in NGINX. The proxy sends a copy and doesn't wait for its response. - At the application level: the old service handles the request itself, also sends it to the new one in the background, compares the two responses and logs the difference. With proxy mirroring you have to build the comparison separately.
# Istio
http:
- route:
- destination: { host: pricing-legacy }
mirror:
host: pricing-v2
mirrorPercentage:
value: 10.0
Dangerous spots:
- Side effects. Even a GET can have side effects (counters, cache). If you mirror POSTs, the shadow version must write to a separate DB, send events to a separate topic or not at all, and call external providers through a stub. Istio appends
-shadowto the mirrored request'sHost, which you can use to tell them apart. - Downstream load. The shadow version calls other services too, so their load doubles. Start with a small
mirrorPercentage. - Personal data. Real requests go to the new environment, so it must be protected at the prod level too.
- Comparison noise: timestamps, random IDs, lists in different order. If the diffing code doesn't normalize these, you get 30% "differences" and nobody looks anymore.
Shadow traffic doesn't replace a canary: it doesn't answer the user, so it doesn't show the new version's full behavior in the real flow. But as a safe stage before a canary it is very useful.
Sign up to mark studied questions and save your progress.