The Shadow Traffic Diff Analyzer (STDA) is a system for safely validating new service versions (e.g., v2 API) by routing a subset of production traffic to both the primary (v1) and shadow (v2) endpoints in parallel ("shadowing"). It captures responses, performs schema-aware comparisons (structural and semantic diffs guided by JSON Schemas), applies configurable tolerance rules to ignore benign differences, and triggers alerts on significant divergences.
Goals:
Detect regressions early (e.g., schema breaks, value drifts).
Support 99.9%+ compatibility before full rollout.
Scale to millions of requests/min with low latency overhead (<50ms added).
Key Assumptions:
Responses are JSON.
Schemas are versioned and stored in a registry (e.g., JSON Schema Store).
Traffic is HTTP/REST; extensible to gRPC/Protobuf.
Deployed as a sidecar (e.g., Envoy/Istio proxy) or API gateway filter.
High-Level Architecture
code
[Production Traffic] --> [Router/Proxy] --> Primary (v1) & Shadow (v2)
|
v
[Response Collector] --> Kafka/Redis (raw responses + metadata)
|
v
[Schema Fetcher] <-- [Schema Registry] (Confluent Schema Registry / Postgres)
|
v
[Diff Analyzer] <-- [Tolerance Rules Config] (YAML/JSON in GitOps repo)
|
v
[Metrics Store] (Prometheus + ClickHouse for diffs)
|
v
[Alerting Engine] --> Slack/PagerDuty + [Dashboard] (Grafana)
Components:
Router/Proxy: Envoy/Istio sidecar. Mirrors ~1-10% traffic to shadow. Adds correlation ID (e.g., X-Correlation-ID).
Response Collector: Buffers responses (headers, body, status, latency). Publishes to Kafka topic partitioned by service/version.
Schema Fetcher: Resolves schemas via subject/version (e.g., service-v1, service-v2).