In Plain Words
Your rewritten code passes every unit test, and you still don't know what it does with the requests production actually sends. Shadow testing finds out by running the new code on real traffic while every user keeps getting answers from the old code.
GitHub's Scientist library gives the two sides useful names. The current code is the control and the new code is the candidate. A shadowed request runs through both, the caller receives the control's result, and the candidate's result is compared and then thrown away. If the candidate crashes or disagrees, the difference lands in a report.
Side effects set the limit. The candidate does real work on real requests, so anything it writes is written for real. Scientist's README is blunt about it: "Scientist is only safe for wrapping methods that aren't changing data."

How It Works
- Pick a sample of requests. Istio's
mirrorPercentagefield and jsonsplit'sSetMarshalCallRatioboth let you shadow a fraction of traffic instead of all of it. - Send a copy to the candidate off the critical path. Envoy's mirroring is "fire and forget" and "will not wait for the shadow cluster to respond before returning the response from the primary cluster."
- Return the control's result to the caller, every time.
- Compare and record. Scientist compares results, measures wall and CPU time, and records exceptions the candidate raises.
- Fix each difference, raise the sample, and switch over only when the reports stay quiet.
Where the copy happens decides what you can learn from it:
| Layer | Examples | What you learn | What you don't |
|---|---|---|---|
| Proxy mirroring | Istio mirror, Envoy request_mirror_policies, nginx mirror | The candidate's load, errors and latency on real traffic. Envoy collects its normal statistics for the shadow cluster. | Whether its answers are right. Shadow responses are discarded (nginx: "Responses to mirror subrequests are ignored.") |
| Comparing proxy | Diffy, built at Twitter | Response differences between whole services, with noise measured separately | Anything inside one process; it needs three running instances |
| In-process | Scientist (Ruby), jsonsplit (Go) | Exact result differences per call | Paths you can't wrap in code, and paths that write data |
Here is the in-process form, run on Go 1.27.3 with jsonsplit. In CallBothButReturnV1 mode the codec calls encoding/json and encoding/json/v2 on each call, returns v1's bytes, and reports any difference. Order is struct { ID string; Items []string }, and the jsonsplit version is v0.0.0-20260814182812-9b1aeb428384:
var codec jsonsplit.Codec
codec.SetMarshalCallMode(jsonsplit.CallBothButReturnV1)
codec.ReportDifference = func(d jsonsplit.Difference) {
fmt.Printf("shadow diff: v1=%s v2=%s\n", d.JSONValueV1, d.JSONValueV2)
}
b, _ := codec.Marshal(Order{ID: "A1"})
fmt.Printf("returned: %s\n", b)shadow diff: v1={"ID":"A1","Items":null} v2={"ID":"A1","Items":[]}
returned: {"ID":"A1","Items":null}The caller got v1's null. The report shows v2 would have sent [] for the same nil slice, one of the v1 and v2 behavior differences a migration has to settle before v2 serves anyone. The jsonsplit migration guide runs this mode on 10% of calls.
Two instances of the same code can still disagree. Diffy handles that by sending each request to a candidate, a primary running known-good code and a secondary running the same known-good code. Primary-versus-secondary disagreement is noise; only disagreement beyond that rate counts. Scientist suggests the same calibration: start with an experiment whose two blocks both call the control.
Why It Matters
Tests check the inputs someone thought to write. Shadow testing checks the inputs production sends, which is why it shows up wherever a rewrite has to match old behavior exactly: Scientist exists for "carefully refactoring critical paths", jsonsplit for moving Go services from encoding/json to v2, and Amazon SageMaker shadow tests let teams check a new model's latency and error rate before promoting it.
Proxy mirroring on its own gives you a load test on real traffic. Correctness needs a comparison step on top, from Diffy or from code inside the service. Budget for what the candidate costs as well, because it consumes real capacity, sees real user data and repeats any write it makes. For write paths Scientist's maintainers update both the old and new systems at write time and compare at read time. Istio and Envoy append -shadow to the Host header of mirrored requests so logs can tell the copies apart. The idea also fits storage: trialling Valkey 9.2 forkless snapshots on a backup replica feeds it the primary's real write stream and compares save behavior before the primary changes.
Origin
In May 2008 Facebook described a "dark launch" period for Facebook Chat: pages connected to the chat servers, queried presence and simulated message sends "without a single UI element drawn on the page" before turning it on for seventy million users. Martin Fowler's 2020 Dark Launching entry lists parallel running of old and new code as one use of the technique, and notes that the term has drifted to cover canary releases as well.
Common Confusions
| Term | What it is | How it differs from shadow testing |
|---|---|---|
| Dark launch | Calling new back-end behavior from real user flows without users being able to tell, usually to measure load (Fowler) | Broader. Comparing results is one use; Facebook's 2008 dark launch simulated load with no UI and describes no result comparison. Some teams also use it loosely for canary releases. |
| Canary release | Rolling a new version out to a small subset of users before everyone | Those users receive the new version's responses. In shadow testing, nobody does. |
| A/B testing | Users split into cohorts, each sent consistently down one code path, with aggregate behavior compared | Measures how users react to visible variants. Shadow testing measures how two versions behave on the same request. |
| Feature flag | A switch that changes system behavior without changing code | A mechanism, not a test. Flags often turn a shadow run or dark launch on and off. |
| Golden file testing | Comparing a program's output with a stored reference file in tests | Fixed inputs before deploy. Shadow testing compares two live implementations on production input; the jsonsplit guide uses golden tests first, then a shadow run. |