Shadow-Traffic Comparison
Mirror real requests to old and new code, compare outputs, and cut over only when they match.
Problem
Coding agents can now rewrite or port a whole service in days, producing far more code than anyone can review line by line. Tests only check the behaviour someone thought to write down, while real traffic exercises edge cases nobody listed. A big-bang cutover risks an outage, and reading every line is not possible at that size.
- Agent-written code is too large to review in full.
- Test suites encode only known behaviour.
- Real traffic has edge cases nobody listed.
- Side effects such as writes and emails can’t safely run twice.
Solution
Put a thin routing layer in front of the service. Every request goes to the current system, whose response is returned to the user, and is mirrored to the new system, whose response is only recorded. A comparator normalizes fields that may legitimately differ, such as timestamps, ids and ordering, and logs every mismatch with its input. Each class of mismatch becomes a failing test and a task for the coding agent, which fixes it and redeploys. The loop repeats until the mismatch rate stays below an agreed threshold over enough traffic. Writes go to a copy or are stubbed. Traffic then shifts to the new system in steps, with the old one kept as a fallback.
Diagram
Users only ever see the old system's answer. The new system earns the switch by matching it on real traffic.
When to use
Use it when
- Replacing a live service or major component (rewrite, port, upgrade)
- Agent-written changes too large to review line by line
- Behaviour is visible as requests and responses
- Side effects can be stubbed or pointed at a copy
Avoid it when
- New features with no existing behaviour to compare against
- Systems dominated by side effects that can't be isolated
- Very low traffic; replay recorded traffic instead
Trade-offs
Gains
- Large agent-written changes verified without reading every line
- Real edge cases found before users hit them
- A clear, measurable bar for cutting over
Costs
- Extra infrastructure that is thrown away afterwards
- Normalization rules need care, or they hide real differences
- Rare paths may need recorded traffic to be exercised
Worked example
The Linkwatch team uses coding agents to port its redirect API from Python to Rust.
- RouterA thin Python layer mirrors 100% of read traffic to the Rust service. Responses are compared after normalizing timestamps and header order.
- Day 13.1% of responses differ. The biggest cause is how the two versions encode Unicode characters in URLs.
- Agent loopEach mismatch class becomes a failing test. The agent fixes it and the Rust service is redeployed daily.
- Day 120.02% mismatch over 40 million requests. The remaining cases are reviewed, judged harmless and recorded.
- CutoverTraffic shifts 1% → 10% → 100% over a week. The Python service stays on standby as a fallback for two more weeks.
Failure modes
| Failure | Symptom | Mitigation |
|---|---|---|
| Noisy diffs | Thousands of mismatches from timestamps or ids | Normalize fields that legitimately differ before comparing |
| Over-normalization | Real differences hidden by comparator rules | Review normalization rules and keep a raw sample |
| Side effects run twice | Duplicate writes or emails from the shadow | Point shadow writes at a copy or stub them |
| Rare paths never exercised | Cutover breaks a low-traffic endpoint | Replay recorded traffic for rare endpoints before cutover |