Agentic Pattern Libraryby Vikas Goyal
← All patterns
68

Shadow-Traffic Comparison

Also known as: traffic mirroring, dark launch, parallel run, differential testing

Mirror real requests to old and new code, compare outputs, and cut over only when they match.

TrackAI-native software delivery FamilyVerify Maturity Established ChangesVerification
01

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.
02

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.

03

Diagram

Usersreal requests Routermirror 100% Old systemanswers users New systemanswer recorded Comparenormalize · diff Coding agentmismatch → failing test → fix Cut over1→10→100% mirror response to user clean

Users only ever see the old system's answer. The new system earns the switch by matching it on real traffic.

04

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
05

Trade-offs

Latency Mirroring is asynchronous; users wait only for the old path
Cost Double compute for the length of the trial
Complexity Router, comparator and normalization rules
Reliability Cutover backed by matching behaviour on real traffic

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
06

Worked example

Scenario
The Linkwatch team uses coding agents to port its redirect API from Python to Rust.
  1. RouterA thin Python layer mirrors 100% of read traffic to the Rust service. Responses are compared after normalizing timestamps and header order.
  2. Day 13.1% of responses differ. The biggest cause is how the two versions encode Unicode characters in URLs.
  3. Agent loopEach mismatch class becomes a failing test. The agent fixes it and the Rust service is redeployed daily.
  4. Day 120.02% mismatch over 40 million requests. The remaining cases are reviewed, judged harmless and recorded.
  5. CutoverTraffic shifts 1% → 10% → 100% over a week. The Python service stays on standby as a fallback for two more weeks.
07

Failure modes

FailureSymptomMitigation
Noisy diffsThousands of mismatches from timestamps or idsNormalize fields that legitimately differ before comparing
Over-normalizationReal differences hidden by comparator rulesReview normalization rules and keep a raw sample
Side effects run twiceDuplicate writes or emails from the shadowPoint shadow writes at a copy or stub them
Rare paths never exercisedCutover breaks a low-traffic endpointReplay recorded traffic for rare endpoints before cutover