TL;DR — Key Takeaways
- Traditional dependency mocks can become less accurate as upstream services deploy more frequently, creating a growing gap between test behavior and production reality.
- Traffic-based mocking reverses that relationship by capturing real upstream interactions after deployments and regenerating mocks from observed behavior.
- Connecting recording sessions to CI/CD deployment events enables teams to surface behavioral changes through diffs while keeping integration tests aligned with current upstream services.
Standard dependency mocking has an inverse relationship with deployment frequency. The more often upstream services deploy, the more opportunities there are for mock configurations to drift from current behavior. A service that deploys twice a week creates more potential accuracy events than one that deploys twice a month. More deployments mean more moments when the mock that was accurate yesterday may no longer accurately represent what the service returns today. In standard dependency mocking, higher deployment frequency is a liability for test suite accuracy.

Traffic-based dependency mocking inverts this relationship. When mock configurations are generated from observed real traffic after each upstream deployment, more deployments mean more observation opportunities. Each deployment that triggers a recording session produces mock configurations from current behavior. Higher deployment frequency becomes an asset for test accuracy rather than a threat to it.
That inversion is not incidental. It follows directly from where the behavioral assumptions in the mock come from. The relationship between deployment frequency and mock accuracy runs in opposite directions depending on the source of those assumptions.
What Standard Dependency Mocking Gets Wrong at Scale
In standard dependency mocking, a developer authors what the upstream service returns. The mock is a specification: This request produces this response; this error condition produces this structure; this edge case produces this behavior. The specification is encoded in a mock file, a WireMock mapping, a Pact contract, or an inline test fixture.
The specification is accurate at the moment of authoring. The upstream service does not remain static.
In a microservice architecture where each service deploys on its own cadence, the gap between a mock’s specification and the real service’s current behavior grows with each upstream deployment that the mock does not account for. Some of these deployments announce themselves through changelogs and release notes. Others introduce behavioral changes — new response fields, reorganized error structures or changed header semantics — that the upstream team considers non-breaking and does not document prominently.
The consuming team’s mock stays fixed while the upstream service evolves. The integration test validates compatibility with the mock’s specification, not with the upstream service’s current behavior. As deployment frequency increases, the rate at which this gap widens also increases with it.
This creates a specific failure pattern. The integration test suite grows more comprehensive over time — more test cases, more edge cases, more error conditions covered. The mock configurations underlying those tests become progressively less current as upstream services keep deploying. Coverage improves on paper. Accuracy degrades in reality. The failure mode is a test suite that passes confidently while the behavioral gap between what it validates and what production encounters grows with every sprint.
The Traffic-Based Alternative
Traffic-based dependency mocking changes the source of behavioral assumptions from developer specification to real observed behavior.
Rather than a developer encoding what they believe an upstream service returns, a recording session captures what the upstream service actually returned during real interactions against a staging environment. The recorded request-response exchanges become the mock configurations that subsequent test runs use. The mock reflects observed reality at the time of capture rather than a developer’s interpretation of API documentation at some earlier time.
The inversion in the relationship between deployment frequency and accuracy comes from the recording trigger. In a traffic-based approach, upstream deployments trigger new recording sessions rather than creating accuracy risk. When the payment service deploys a new version, a recording session runs against the updated staging payment service and captures how it currently behaves. The mock configurations for the order service’s payment dependency update from current observed behavior rather than waiting for a developer to notice a changelog entry and manually update a fixture file.
Three properties emerge from this that specification-based mocking cannot provide.
- Completeness Without Annotation: A recording session captures every field the real service returned, including fields the API documentation does not mention, fields that appear only for specific input combinations and fields that beta participants see before they become standard. The developer does not need to know which fields to include in the mock. The observation includes them by definition.
- Non-Deterministic Field Handling From Observation: Real API responses contain fields that vary on every call — generated identifiers, timestamps and request correlation tokens. A mock that includes these verbatim fails every test run because the captured values do not match what the service returns during test execution. Traffic-based approaches identify variable fields by comparing multiple captures of the same interaction. Fields that produce different values across captures are excluded from mock assertions automatically. Fields that are consistent across captures are retained. No manual annotation of variable fields is required.
- Behavioral Drift Surfaces Explicitly: When a recording session runs after an upstream deployment and produces configurations that differ from the previous session’s configurations, the difference is explicit. A field that was renamed appears as a removed field and an added field in the diff. A type that changed appears as a changed assertion. The consuming team sees exactly what changed in the upstream service’s actual behavior, which is more actionable than a changelog entry and more accurate than trying to infer behavioral changes from documentation updates.
The Deployment Trigger Architecture
The accuracy improvement from traffic-based dependency mocking is only realized when the recording sessions are connected to the events that create accuracy risk — upstream service deployments.
A recording session run on a weekly schedule misses upstream deployments that occurred between sessions. A recording session triggered by upstream deployment events catches every deployment that might have changed behavior the downstream mocks depend on.
The architecture for this in a CI/CD environment has three components.
- Upstream Deployment Signaling: When an upstream service’s CI pipeline successfully deploys to staging, it emits a deployment event — a webhook, a repository dispatch event or a message to an event bus — that downstream services can subscribe to. The event carries the service identifier and the staging endpoint where the updated service is running.
- Automated Recording Session: The downstream service’s pipeline subscribes to upstream deployment events and triggers a recording session when one arrives. The recording session runs against the upstream service at the staging endpoint identified in the event, exercises the request patterns the downstream service sends in production, captures the responses and generates updated mock configurations from the observed interactions.
- Diff-Driven Review: The recording session compares new configurations against previous ones and produces a diff. For additive changes — new fields, new optional response properties — the updated mock configurations can be adopted automatically. For structural changes — renamed fields, changed types, removed properties — the diff creates a review task before the downstream service adopts the new configurations because structural changes may require downstream code updates alongside mock updates.
This architecture means that every upstream deployment that changes behavior produces a diff that tells the downstream team exactly what changed and whether action is required. The signal arrives at the upstream deployment event rather than at the next production incident.
Where Traffic-Based Dependency Mocking Fits in the Testing Stack
Traffic-based dependency mocking is not a replacement for every form of dependency testing. Its fit varies as per dependency type and testing objective.
For HTTP API dependencies — internal microservice APIs, third-party REST APIs, GraphQL endpoints — traffic-based mocking is the strongest approach because HTTP traffic is directly observable and the behavioral variations that matter are in the request-response exchanges that recording captures.
For infrastructure dependencies — databases, message queues, caches — real service containers through Testcontainers or equivalent tooling typically provide better fidelity than any form of mocking because genuine service semantics (SQL constraints, message ordering guarantees, atomic cache operations) matter for integration correctness in ways that HTTP-level behavioral representations cannot capture.
For contract testing between teams that own both sides of an API boundary and maintain accurate OpenAPI specifications, specification-based approaches such as Pact provide structural guarantees through contract verification that traffic-based approaches do not require. Thus, when the specification is current and both teams verify against it, the behavioral accuracy problem is addressed at the contract level.
Traffic-based dependency mocking fills the gap between these scenarios: HTTP API dependencies — particularly third-party APIs — where neither real service calls during testing nor manually maintained specifications reliably keep mock behavior current with upstream service reality.
The Operational Shift
The shift from specification-based to traffic-based dependency mocking is not primarily a tooling change. It is an operational model change.
Specification-based maintenance is reactive. Someone identifies that an upstream service changed, reads what changed, determines which mocks are affected and makes the correct updates. The maintenance burden is proportional to how quickly the team identifies upstream changes and how accurately they interpret their impact on mock configurations.
Traffic-based maintenance is event-driven. Upstream deployments trigger observation sessions that capture current behavior and surface differences from previous configurations. The maintenance burden is proportional to the number of upstream deployment events, but each event requires less human judgment because the diff shows exactly what changed rather than requiring the team to identify it.
Keploy implements this event-driven model through eBPF-based traffic capture at the kernel level, which intercepts HTTP exchanges between services without requiring changes to application code, proxy configuration or test instrumentation. The recording sessions run against staging environments after upstream deployments, generating both test cases and mock configurations from observed interactions. The kernel-level capture makes the approach language- and framework-agnostic — the same recording mechanism works regardless of whether the upstream service is a Go microservice, a Python FastAPI application or a Node.js Express server, and regardless of which HTTP client library the downstream service uses to call it.
For DevOps teams managing integration test accuracy across many services on independent deployment schedules, the operational question is whether the maintenance model scales with the architecture. Specification-based maintenance scales poorly with deployment frequency because the human attention required per upstream deployment stays constant while deployment frequency increases. Event-driven traffic-based maintenance scales better because the human attention required per upstream deployment decreases as the automated observation and diff process handles more of the identification work.
What Changes When Accuracy Improves With Deployment Frequency
The consequence of inverting the relationship between deployment frequency and mock accuracy is a change in what CI pipeline results mean.
In the standard model, a green integration test suite means the application handles mock behavior correctly. Whether mock behavior matches current real service behavior is a separate question and the answer to that question degrades with every upstream deployment that the mock does not account for. Pipeline results and production behavior decouple over time.
In the traffic-based model, a green integration test suite means the application handles behavior that was observed from real upstream services after their most recent deployments. Pipeline results and production behavior stay coupled because the observations that ground the mocks are current.
That coupling is what makes traffic-based dependency mocking the more durable approach for architectures where deployment frequency is high and upstream services evolve continuously. The accuracy of the mock configurations is not a property of when they were written. It is a property of when they were last observed, which — in an event-driven recording architecture — is always after the most recent upstream deployment.

