How do shadow deployments and traffic mirroring validate ML models without affecting production decisions?
A shadow deployment runs a candidate inference release on copies of real production requests while the stable model alone serves the user-visible answer. It lets engineers measure candidate compatibility, latency, capacity and prediction disagreement on realistic inputs without directly placing candidate predictions in the live decision path. It does not automatically remove risk: duplicate side effects, sensitive-data copying, shared dependency load or a poorly isolated mirroring implementation can still hurt production.
Curriculum position: Question 120 established immutable inference packages; Question 121 established staging validation; Question 122 explained rolling, blue-green and canary exposure plus rollback. This lesson focuses specifically on non-authoritative shadow execution, paired-result comparison, sampling bias and safe mirroring operations, not on how to promote live traffic or how to run a general A/B experiment.
Beginner-friendly example
A delivery marketplace currently uses late-risk/r27 to decide whether to warn a customer that an order may arrive late. Team members want to evaluate r28 on today's real traffic before allowing its predictions to affect any checkout.
- Primary path: Customer → gateway → stable
r27→ actual risk decision → customer. - Mirrored path: Gateway or controlled capture service → copy of eligible request → shadow
r28→ metrics/paired comparison store. - Safety rule: Only the stable response is returned to the application. Shadow output cannot send customer notifications, update business records, charge payments or invoke other real-world effects.
This distinguishes shadow traffic from canary routing (Question 122): a 5% canary serves candidate responses to 5% of eligible requests; a 5% shadow copies approximately 5% of requests to the candidate, but stable still serves all users. A standard mirroring gateway such as Istio discards the mirror response; to compare model outputs you must explicitly implement safe shadow-result capture or use a platform capability that stores both outputs. Never assume gateway mirroring automatically supplies paired scores.
Production architecture and ownership
- Request source: Mirror traffic at a gateway/service mesh, a dedicated inference gateway or a controlled asynchronous capture/replay service. Pick a location where request schema, identity and event-time context are trustworthy.
- Stable serving: Keep the production decision path independent. Do not wait for shadow inference to finish or incorporate its score into the returned response.
- Shadow serving: Run an independently versioned candidate image/model/config and, where practical, separate compute, concurrency limits and feature-store quotas. Tag telemetry with stable and shadow release IDs.
- Safe comparison: Generate a correlation ID, capture both predictions through an authorized low-retention pipeline, normalize comparable fields and record why a request could not be paired.
- Operational isolation: Disable or sandbox writes, notifications, webhook calls, mutations and chargeable actions. Apply traffic sampling, backpressure, bounded queues, circuit breakers and a fast disable switch for the shadow branch.
- Security: Enforce privacy/legal authorization for copied inputs, minimize or tokenize personal information, restrict access, encrypt protected captures, redact logs and set retention limits.
*Important:* If the gateway mirror cannot be configured with a separate reduced-privilege identity or strict egress policies, deploy the candidate in an environment that independently blocks side effects. HTTP request copying by itself is not a safety boundary.
Step-by-step shadow experiment
- Define an exact hypothesis. Example: candidate r28 has no higher timeout rate than r27 and its p95 compute latency is at most 220 ms on the same incoming request mix, while its score disagreement is explainable.
- Freeze release identity and feature contract. Use the tested image/model digests from earlier lessons and ensure both models receive semantically comparable features. Pin or record external feature timestamps; model differences otherwise mix with feature freshness differences.
- Define eligible traffic and exclusions. Exclude unsupported payloads and requests whose duplication is unsafe. Document the sampling key (e.g., stable hash of order ID) and rate; keep repeated entity-level traffic consistent when analysis demands it.
- Warm and isolate shadow instances. Verify readiness, limits, artifacts and sandboxed outbound access before enabling copying. Route no authoritative responses to the candidate.
- Begin at a low mirror percentage. For example, 1%, then 5%, 25%, up to a representative test rate only if resource budgets allow. This changes copied load, not user-visible prediction exposure.
- Match paired observations. Join on an opaque request ID with a bounded time window; track stable result, shadow result, processing status, timestamps, input/feature revision and both model versions. Count dropped, timed-out and unpaired shadow requests rather than hiding them.
- Review operational and ML guardrails. Measure actual mirror receipt, p95/p99 latency, errors, saturation, feature failures, output/schema validity and prediction disagreement by geography or entity type.
- Complete and decide. Shadow evidence may justify proceeding to a controlled canary, more offline labeling, or rejection. It is *not* proof of business outcome uplift because the candidate did not control actions or user behavior.
Numerical example 1: sampling and extra compute
Assume the production endpoint receives 600 requests/second. A 10% mirror runs for 20 minutes.
- Production still receives
600 × 1,200 = 720,000authoritative requests. - Expected shadow requests =
600 × 0.10 × 1,200 = 72,000, about 60 shadow RPS if arrivals are approximately uniform. - Total inference invocations across both paths =
720,000 + 72,000 = 792,000, a 10% increase relative to one inference per request. - If each independent shadow worker can sustain 25 RPS at the desired p95 and planning utilization is 75%, budget per worker =
25 × 0.75 = 18.75 RPS. Estimated shadow worker count =ceil(60/18.75) = 4. - If a shadow request requires two feature reads, the experiment may add approximately 120 feature reads/second; confirm the feature service's spare capacity. Four workers do not help if an upstream quota is already saturated.
Operational decision: rate-limit or disable mirroring when shared dependencies approach a critical production budget. Mirror percentage must be measured from observed forwarded and accepted requests; a configured 10% does not guarantee 72,000 successfully processed results.
Numerical example 2: pairwise model disagreement
Of the 72,000 copied requests, suppose 70,000 have both usable stable and shadow predictions. A production policy flags an order when predicted lateness risk ≥ 0.70. Paired results:
- Both models flag: 12,000.
- Neither flags: 53,000.
- Only stable flags: 3,000.
- Only shadow flags: 2,000.
- Check:
12,000 + 53,000 + 3,000 + 2,000 = 70,000. - Disagreement count =
3,000 + 2,000 = 5,000; disagreement rate =5,000/70,000 = 7.14%. - Stable flags
12,000 + 3,000 = 15,000→ 21.43%; shadow flags12,000 + 2,000 = 14,000→ 20.00%. - 2,000 requests lack a valid pair: pair coverage =
70,000/72,000 = 97.22%. Investigate whether these missing pairs cluster in the slowest or most important requests.
The 7.14% disagreement is not a 7.14% error rate: without reliable ground-truth labels, neither model's correctness is established. Examine disagreement by high-risk segment, use future labels on time-aligned examples, and maintain a separate live-outcome experiment only after the release is operationally safe.
Numerical example 3: shadow overhead and containment
Suppose a mirror collector queues candidate requests at 80 RPS, while the shadow fleet can process 60 RPS, for 3 minutes.
- Backlog growth =
(80 - 60) × 180 = 3,600requests. - If the source rate returns to 40 RPS, spare capacity =
60 - 40 = 20 RPS; ideal catch-up takes3,600/20 = 180 seconds. - During that period, paired results may be delayed and some requests may be stale. A bounded queue that drops new shadow copies protects the primary service more effectively than unbounded growth.
- Never let a full shadow queue block an authoritative inference request. Enforce nonblocking enqueue or independent capture resources and surface the loss as a measurable sampling limitation.
For example, if candidate instance-hour pricing is an *illustrative* $0.40 and four workers run 20 minutes, extra worker compute is 4 × (20/60) × $0.40 ≈ $0.53, excluding networking, observability, storage, broker and feature-service costs. The apparent low compute bill says nothing about the real risk of shared capacity saturation.
Shadow versus canary versus offline replay
- Offline replay: Historical records are scored in a separate controlled run. Low production coupling and strong repeatability, but cannot naturally reproduce today's live request shapes and real downstream latency.
- Shadow execution: Candidate sees near-live request copies; its outputs do not decide user behavior. Useful for compatibility, operational readiness and candidate/stable disagreement. Requires strict side-effect isolation and may increase real-time resource usage.
- Canary: Candidate actively serves a selected share of users and therefore exposes them to its decisions. Necessary for some end-to-end business outcomes; use Question 122's progressive gates and rollback procedures.
- A/B testing: A causally interpretable comparison usually requires randomized, stable assignment and outcome measurement. A shadow request copy is *not* an A/B experiment: users experience the stable policy, so candidate-caused conversions, cancellations, fraud interventions or downstream feedback cannot be observed directly.
Feature and state consistency
- Prefer capturing a single logical feature snapshot for both paths when feasible, or record versions/timestamps so differences caused by fresh versus stale features are not misattributed to model weights.
- Record timeouts, preprocessing mismatches, unknown categories and schema coercion. A successful response with a different feature definition is not a valid paired model comparison.
- For stateful models, avoid sharing mutable state or side effects between primary and shadow. Replayed events can double-count a user session unless state stores and sink identities are isolated.
- Beware feedback loops: even shadow scores logged into production feedback tables can indirectly affect future training or user actions if downstream jobs treat them as authoritative. Mark and segregate shadow records.
Safe error handling and shutdown
Failure: mirroring increases production feature latency
- Investigate shared feature-store load, request pool saturation and connection quotas.
- Reduce shadow rate to zero and verify stable p95/p99 returns to baseline; reserve a dedicated feature read budget for future tests.
Failure: duplicate webhook or payment
- Treat as a serious isolation failure. Stop mirroring, revoke shadow write permissions, inspect the side-effect ledger, reconcile duplicates and add a network/credential-level safeguard before any retry.
- Hiding the shadow response is not enough when the handler itself performs mutations.
Failure: candidate predicts different scores only in one region
- Validate schema, units, data completeness, request mix and feature freshness by region. Compare matched requests and investigate threshold-crossing events with delayed ground truth. Do not declare model failure solely from disagreement.
Failure: high reported agreement but low pairing coverage
- Check dropped mirrors, timeouts, correlation ID propagation, storage/write failures and capture exclusions. Missingness may be nonrandom; publish coverage by segment before interpreting the paired sample.
Failure: shadow result latency appears unusually low
- Verify whether instrumentation measures only model compute rather than end-to-end mirrored receive-to-result time, and whether the shadow fleet enjoys a warmer cache or different resources. Compare like-for-like measures.
Practical minimal configuration (Istio illustrative example)
YAMLapiVersion: networking.istio.io/v1 kind: VirtualService metadata: name: risk-inference spec: hosts: - risk-inference http: - route: - destination: host: risk-inference subset: stable weight: 100 mirror: host: risk-inference subset: shadow mirrorPercentage: value: 10.0
This captures the routing concept, not a complete deployable system: corresponding DestinationRule subsets, Services, workloads, authentication, resource quotas and controls are required. Under Istio mirroring, shadow responses are discarded and mirrored requests are sent out of the primary response path. It does not provide paired score storage or write isolation by itself. Verify syntax against the target Istio version.
Shadow experiment monitoring and exit criteria
- Primary safety: stable p95/p99, error rate, dependency latency and availability must not materially degrade versus baseline.
- Mirror health: configured sampling versus delivered and successfully processed counts, queue lag, drops, mirror timeout rate, p95/p99, CPU/GPU memory and additional feature-store pressure.
- Data and comparison: matched pairs, coverage by region and request type, feature snapshot parity, invalid outputs, disagreement rates and high-impact threshold crossings.
- Governance: approved test purpose, exact release digests, traffic eligibility, data minimization, retention, side-effect isolation, kill switch, operator and result review.
- Decision: pass only when operational thresholds and coverage requirements are met; absence of delayed labels means *quality benefit is still unproven*. Progress to a controlled canary or a properly designed randomized experiment only if justified.
SageMaker AI provides managed shadow tests that mirror a configurable portion of requests to a candidate and return only the production variant response. It can capture comparisons, but feature support varies: its documentation excludes certain serverless, asynchronous, multi-model and other endpoint configurations. The Istio implementation is more general infrastructure mirroring and requires your own model-specific comparison and safety setup.
Trade-offs and common mistakes
- Good: Catch production-only schema, performance, resource and feature issues without serving candidate decisions.
- Cost: Extra inference, storage, network and observability resources, sometimes substantial at 100% mirroring.
- Risk: Shared dependency contention, privacy exposure, hidden write side effects, unbounded queues and misleading “exactly same request” assumptions.
- Mistake: Treating shadow responses as user-visible, or treating a shadow experiment as proof of causal business lift.
- Mistake: Interpreting only successfully paired predictions while ignoring dropped and timed-out mirrors.
- Mistake: Using unmatched feature snapshots or model versions and attributing all differences to the candidate model.
- Mistake: Copying real personal data without approved retention or access policies.
- Mistake: Assuming basic gateway mirroring automatically captures both model outputs.
- Mistake: Using shared credentials with production write permissions.
- Mistake: Promoting directly because predictions largely match, without the production canary and rollback gates from Question 122.
Takeaway: Shadow deployment is a side-effect-free, non-authoritative production rehearsal. Mirror bounded real requests, isolate effects and resources, measure paired coverage and operational health, and treat the results as readiness evidence—not proof of improved user outcomes.
Sources & Research References
Learning Sequence
MLOps Curriculum
How do you run trustworthy online A/B tests for production ML model versions?
Explore Related Questions
Deepen your understanding across related MLOps topics.