A shadow deployment runs a new version of a service next to the live one and sends it a copy of real production traffic. Users only ever get responses from the live version. The shadow’s responses are recorded or compared, then thrown away. It lets you see how new code behaves under real load and real data with zero user impact.

Every testing environment is a guess about what production looks like. Staging has cleaner data, fewer users and none of the odd clients that have been hitting your API for five years. A shadow deployment stops guessing. It takes the actual requests your users send, right now, and plays them against the new code.

That is why it is the go-to approach for the scary changes: rewriting a service in a new language, swapping a database, upgrading a framework two major versions at once. This guide covers how traffic mirroring works, how to set it up with Istio, Linkerd and NGINX, the write problem that catches almost everyone, how shadow compares to other deployment strategies, and a lighter way to get the same result with recorded traffic.

What is shadow deployment?

Shadow deployment, also called shadow mode or dark traffic testing, is a release technique where the new version receives a mirrored copy of live requests but never answers users. It is a pre-release test on real traffic, not a rollout. Once the shadow proves itself, you still release it with another strategy such as canary or blue-green.

The live version (sometimes called the primary) handles every request exactly as before. Somewhere in the path, a proxy duplicates each request and fires the copy at the shadow version. The shadow processes it like normal. Then its response gets logged, compared to the primary’s, or simply dropped.

What you get out of it depends on what you measure:

  • Correctness: do the shadow’s responses match the primary’s for the same input?
  • Performance: how do latency, CPU and memory look under real request patterns?
  • Stability: does it crash, leak memory or hit timeouts on inputs your tests never covered?

The term shadow traffic just means that mirrored copy of requests. You’ll see it called mirrored traffic or dark traffic as well.

How traffic mirroring works

Traffic mirroring happens at a proxy that sits in front of the service: a service mesh sidecar, an ingress controller or a load balancer. For each incoming request, the proxy forwards the original to the live version and sends a copy to the shadow asynchronously. It waits only for the live response, so the shadow cannot slow down or break what users see.

Traffic mirroring sending a copy of each request to a shadow version while users get the live response

The “fire and forget” part is what keeps it safe. The proxy doesn’t wait for the shadow to answer. If the shadow is slow, crashes or returns garbage, the user never notices. Most proxies also tag mirrored requests (Istio, for example, appends -shadow to the Host header) so the shadow can tell it is receiving copies.

A few details worth planning for:

  • Sampling. You rarely need 100% of traffic. Mirroring 10% to 20% is usually enough to spot problems and costs a lot less.
  • Capacity. The shadow needs enough resources to handle the mirrored share, or it will fall over and give you useless results.
  • Comparison. Mirroring alone doesn’t tell you if responses match. You need something that captures both responses and diffs them, ideally ignoring fields that always differ (timestamps, request IDs).
  • Request bodies. Some proxies only mirror headers and small bodies by default. Check the limits if you send large payloads.

Shadow deployment in Kubernetes: Istio, Linkerd, NGINX

In Kubernetes, traffic mirroring is set up in the networking layer, not in the Deployment. Istio uses the mirror and mirrorPercentage fields on a VirtualService. Linkerd and other Gateway API implementations use the RequestMirror filter on an HTTPRoute. NGINX uses the mirror directive. In all three, the shadow runs as its own Deployment and Service.

Start by deploying the shadow version as a separate Deployment with its own Service, for example orders-shadow. It should not be part of the main Service’s selector, or it will start getting real traffic.

Istio traffic mirroring

Istio has had mirroring for years and it is the most common setup:

yaml

All user traffic goes to v1. Twenty percent of requests are copied to v2. Istio sends the copy without waiting for its response and adds -shadow to the Host header, which is handy if you want the shadow to log or behave differently for mirrored calls.

Linkerd traffic mirroring support

Linkerd’s routing has moved to Gateway API’s HTTPRoute, and the Gateway API spec defines mirroring through a RequestMirror filter on a route rule. Gateway API 1.2 also added percentage-based mirroring, so you can mirror a fraction of requests instead of all of them. Support for specific filters varies by Linkerd release, so check the release notes for your version before relying on it. The route looks like this in any implementation that supports the filter:

yaml

NGINX traffic mirroring

If you are not on a mesh, NGINX’s mirror directive does the job at the edge:

nginx

Keep the timeouts short on the mirror location. NGINX handles the mirror as a subrequest, and a slow shadow can tie up worker connections. Envoy, Traefik and HAProxy have similar features if your stack uses one of those instead.

The write problem: databases, emails, payments

Traffic mirroring copies every request, including the ones that change things. If the shadow version writes to the same database, sends emails, publishes events or charges cards, each mirrored request does it a second time. Before turning on mirroring, every side effect in the shadow must be isolated, stubbed or disabled.

This is the part that turns a clever idea into an incident. A user places an order. The live version saves it and sends a confirmation email. The mirrored request hits the shadow, which also saves the order and also sends an email. Now the customer has two orders and two emails, and finance has a problem.

Your options, roughly from easiest to most thorough:

  • Mirror only read traffic. Route GET requests to the shadow and skip POST, PUT and DELETE. Simple, safe, and it covers a lot of bugs. It also misses every bug in the write path.
  • Give the shadow its own database. A copy or snapshot of production. Writes land somewhere harmless, though the data drifts from production the longer it runs.
  • Stub external calls. Point the shadow at fake versions of the email service, payment gateway and message broker. This takes config work for every dependency, and the fakes need to behave realistically.
  • Use a shadow flag in code. Check for the mirrored header and skip side effects. It works, but it puts test logic inside production code, and it’s easy to miss a code path.

There’s also the comparison problem. Even when writes are handled, the shadow’s responses often differ from the live ones for boring reasons: new IDs, timestamps, slightly different ordering. You need a way to ignore that noise and flag the differences that actually matter.

Shadow vs canary vs blue-green

Shadow tests a new version on real traffic with no user exposure, but it never releases anything. Canary releases to a small share of real users. Blue-green releases to everyone at once with instant rollback. Most teams use shadow before canary or blue-green, not instead of them.

Shadow Canary Blue-green
Users get responses from the new version No Some All
User risk None Small All users until rollback
Releases the new version No Yes Yes
Main challenge Side effects of mirrored writes Enough traffic and good metrics Double infrastructure, shared database
Best for Rewrites, migrations, performance checks Gradual, measured release Fast cutover with instant rollback

For the release side, see our guides to canary deployment and blue-green deployment.

Shadow testing with recorded traffic

Shadow testing with recorded traffic captures real production requests once, along with the responses from every dependency, then replays them against the new version with those dependencies mocked. You get the realism of a shadow deployment without running a mirrored copy in production and without any risk of duplicate writes.

Live mirroring has two costs that add up fast. You run a second copy of the service in production for as long as the test lasts, and you spend real engineering time stubbing every database, queue and third-party API so mirrored writes don’t do damage. For a one-off rewrite, that can be worth it. For every release, it usually isn’t.

Recording and replaying gets you most of the same value with far less setup. This is how Keploy works:

  1. Record. Keploy captures real API calls to your service using eBPF, so you don’t change application code. Along with each request and response, it records what the service sent to and got back from its database, cache and other services.
  2. Store. Each call becomes a test case. The dependency traffic becomes mocks tied to that test.
  3. Replay. In CI, or wherever you test, Keploy runs the new version and sends it the recorded requests. When the new version calls its database or another service, Keploy answers from the mocks.
  4. Compare. Keploy diffs the new response against the recorded one, field by field, and lets you mark noisy fields like timestamps so they don’t fail the test.

Keploy recording production traffic and replaying it against a new version with mocked dependencies

Because nothing real is called during replay, the write problem disappears. No duplicate orders, no extra emails, no payment calls. And because the requests came from production, you still catch the odd inputs that hand-written tests miss.

This doesn’t fully replace live shadowing. If you need to see how a new version performs under real concurrent load on real infrastructure, mirror the traffic. But for catching functional regressions before every release, replay is cheaper, safer and easy to run on every pull request. We go deeper on the practice itself in what is shadow testing, and environment replay covers running a whole set of recorded services together.

You can see the full record and replay flow on Keploy’s API testing page.

FAQs

Is shadow deployment the same as dark launching?

Not quite. In a shadow deployment, users never receive responses from the new version, because it only processes copies of their requests. In a dark launch, the new code runs in production and real users do use it, but the feature is hidden or limited, usually behind a feature flag. Both test new code in production, but only shadow keeps users completely away from the new version.

Does traffic mirroring affect users?

Not directly. The proxy sends the copy to the shadow without waiting for its response, so users only see the live version’s answer and its normal latency. Users can still be affected indirectly if the shadow writes to shared systems, such as sending a duplicate email or creating a duplicate record, or if mirroring overloads a shared database. That is why side effects must be isolated first.

What is shadow traffic?

Shadow traffic is a copy of real production requests sent to a version of a service that does not answer users. It is also called mirrored traffic or dark traffic. Teams use it to test new code against real request patterns, payloads and volume before releasing it.



More Stories

No posts found matching ""