Scrivio Interview library
DesignAdvanced7 min read · updated 12 November 2026

Across 150 services, teams mock dependencies differently: some call shared staging environments, some use WireMock, some mock HTTP clients in unit tests. What testing standard would you set for service-to-service calls?

I would set a layered standard. Unit tests mock dependencies at our own client interface; integration tests exercise the real HTTP client against HTTP-level stubs, WireMock or MockWebServer, to cover serialisation, headers, errors and timeouts; and consumer-driven contract tests between consumers and providers replace most calls to shared environments. Shared staging stays only for a small smoke suite. The platform provides a shared library of stub helpers and fault scenarios per internal API, and we measure flakiness and test time to show the standard's effect.

Why this question is asked

With 150 services, every team has solved 'how do we test calls to other services' in its own way, and each way fails differently. Teams that call shared staging have slow, flaky builds that break whenever another team deploys. Teams that only mock their HTTP client in unit tests have fast builds and production incidents from wrong paths and field names. Interviewers ask this design question at senior level because the answer must give each kind of test a clear job, not just pick a favourite tool. In this answer, we will look at what each current approach catches and misses, define the layers of the standard and what each layer is responsible for, describe the shared library that makes it cheap, and finish with how to roll it out and prove it worked.

1What Each Current Approach Catches and Misses

It helps to start by being fair to each approach, because each team chose it for a reason. Mocking the HTTP client in unit tests is fast and lets us test our own logic, such as what happens when the customer is not found. But no request is ever sent, so it cannot catch a wrong URL, a missing header, a JSON mapping error or a missing timeout. WireMock stubs exercise the real client over real HTTP, so they catch all of those, but hand-written stubs can drift from the real provider. Calling a shared staging environment uses the real provider, so it catches drift, but it is slow, it depends on whatever version is deployed there, and it fails whenever staging is down or another team's test data gets in the way.

So the problem is not that any one approach is wrong. It is that each is being asked to do every job. The standard assigns each job to the cheapest test that can do it reliably.

2The Layers of the Standard

The first layer is unit tests that mock at the client interface. Our code depends on an interface such as CustomerClient, with a method like find(id). In unit tests of the code that uses it, we replace the interface with a mock or a fake, and test our logic for each possible outcome: found, not found, error. These tests never involve HTTP.

The second layer is client integration tests with HTTP-level stubs. For each client implementation, we start WireMock or MockWebServer and run the real client against it, covering the request path and method, headers such as authentication and correlation ids, serialisation in both directions, error status mapping, timeouts and retries. These tests are where HTTP behaviour is tested, and nowhere else needs to repeat it.

The third layer is consumer-driven contract tests. The consumer's expectations are recorded as contracts, with Pact or Spring Cloud Contract, and the provider's pipeline verifies them. This is what keeps the second layer's stubs honest, and it replaces most of what teams used shared staging for: checking that both sides agree on the API.

The fourth layer is a small smoke suite in a shared or production-like environment, a handful of tests per critical journey that check that the real deployed services can talk to each other, with real networking, real security configuration and real service discovery. It runs after deployment, not on every pull request.

Step throughTesting standard for service-to-service calls
  1. Smoke tests in a shared environmentA few critical journeys, after deployment, not per pull request
  2. Consumer-driven contract testsProvider pipelines verify consumer expectations; blocks breaking changes
  3. Client integration tests with HTTP stubsReal client vs WireMock or MockWebServer: paths, headers, JSON, errors, timeouts
  4. Unit tests mocking the client interfaceBusiness logic for each outcome, no HTTP, milliseconds

4 layers, from the top down. Step through them one at a time.

Each layer has one job; the expensive top layer stays small because the layers below do most of the work.

3The Shared Stub Library

A standard that every team must implement from scratch will be implemented 150 slightly different ways. So the platform provides a shared library, and for each internal API, the provider team, or the contract tooling, publishes ready-made stub helpers. A consumer test can then say 'customer 42 exists' or 'the customer service is slow' in one line, and the stubs match the provider's published contract.

Java
// Published by the customer-service team, generated from or checked against their contracts
public final class CustomerServiceStubs {
private final WireMockExtension wm;
public CustomerServiceStubs(WireMockExtension wm) { this.wm = wm; }
public void customerExists(long id, String name) {
wm.stubFor(get(urlEqualTo("/customers/" + id))
.willReturn(okJson("{\"id\":" + id + ",\"fullName\":\"" + name + "\"}")));
}
public void customerMissing(long id) { wm.stubFor(get(urlEqualTo("/customers/" + id)).willReturn(notFound())); }
public void slow(Duration delay) { wm.stubFor(any(urlPathMatching("/customers/.*")).willReturn(ok().withFixedDelay((int) delay.toMillis()))); }
public void resetsConnections() { wm.stubFor(any(anyUrl()).willReturn(aResponse().withFault(Fault.CONNECTION_RESET_BY_PEER))); }
}
// In a consumer's test
stubs.customerExists(42, "Ann");
assertThat(orderService.place(42, lines).customerName()).isEqualTo("Ann");

Notice that the library includes fault scenarios as well as happy paths. Standard faults, slow responses, connection resets, 503 sequences for retries, mean every consumer tests its resilience the same way, and a new team gets that coverage for free. The library also fixes the platform details once: dynamic ports, @DynamicPropertySource wiring and the internal authentication header.

4Rolling It Out and Measuring the Effect

I would roll this out where it hurts most first. The services whose builds fail most often because of staging, and the provider interfaces involved in the most incidents, go first. For each, the provider team publishes contracts and stub helpers, and the consumers move their staging-dependent tests down to client integration tests with the stubs. Teams that already use WireMock mostly need to switch to the shared helpers and add contract verification. Teams that only mock clients need to add the client integration layer.

Measurement is what keeps the standard from being a slide. Before starting, I would record per team the pipeline duration, the share of builds that fail for reasons unrelated to the change, and incidents caused by integration breaks between services. After each team moves, the same numbers show the effect: typically pipelines get shorter because staging calls disappear, flakiness drops for the same reason, and integration incidents drop because contracts catch breaking changes before deployment. Showing those numbers per team is the best argument for the teams that have not moved yet.

5Follow-up questions

Why not keep using staging for integration testing, since it is the real thing?

Because it is the real thing only in theory. Staging runs whatever versions were last deployed, its data is shared and changed by many teams, and any outage blocks everyone's builds. It also gives feedback late. Contracts give the same assurance, that both sides agree on the API, in each team's own pipeline, in minutes. Staging remains useful for a small set of smoke tests of the real wiring.

Who owns the stub helpers, the consumer or the provider?

Ideally the provider, because the provider knows the API and can keep the helpers in line with its contracts and releases. Consumers contribute scenarios they need through pull requests. If stubs are generated from contracts, ownership follows the contracts.

Do we need contract tests for internal APIs that only one consumer uses?

Often yes, because even one consumer can be broken by a provider change, and the cost of a contract between two Spring services is small. For APIs that are truly owned and deployed together by one team, a shared integration test may be enough.

6Conclusion

In this answer, we designed a standard for testing service-to-service calls across 150 services. Unit tests mock at the client interface and test business logic. Client integration tests run the real client against WireMock or MockWebServer to cover serialisation, headers, errors and timeouts. Consumer-driven contract tests keep stubs honest and replace most calls to shared staging, which remains only for a small smoke suite. A shared library of stub helpers and fault scenarios per internal API makes the standard cheap to follow, and measuring pipeline time, flakiness and integration incidents shows whether it works.

What to say in the interviewAbout 90 seconds aloud

Open with

I'd give each kind of test one job. At the bottom, unit tests mock our own client interface, like CustomerClient.find, and test business logic for each outcome: found, not found, error.

Then, if they want more

No HTTP there. Next, every client implementation gets integration tests with HTTP-level stubs, WireMock or MockWebServer, which run the real client over real HTTP. That's where we test paths, headers like auth and correlation ids, JSON in both directions, error mapping, timeouts and retries, and nowhere else repeats it.

Third, consumer-driven contract tests with Pact or Spring Cloud Contract: consumers record what they rely on and provider pipelines verify it, so stubs can't silently drift and breaking changes are caught before deployment. That replaces most use of shared staging.

Staging, or a production-like environment, keeps only a small smoke suite for critical journeys after deployment, because it's slow and flaky as a gate.

To make it cheap, the platform ships a shared library where each provider publishes stub helpers for its API, like customerExists or customerMissing, plus standard fault scenarios such as slow responses, connection resets and 503 sequences, with dynamic ports and property wiring done once.

I'd roll it out starting with the teams most hurt by staging and the interfaces behind the most incidents, and I'd measure pipeline time, unrelated build failures and integration incidents before and after per team to show the effect.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Across 150 services, teams mock dependencies differently: some call shared staging...": https://scrivio-interview-library.netlify.app/java/integration-testing/fd19247bab/