Scrivio Interview library
ScenarioAdvanced7 min read · updated 12 November 2026

Two teams keep breaking each other's APIs despite integration environments. How would you introduce contract testing across 40 services?

I would start with the interfaces that break most often, not with all 40 services at once. The platform provides a contract broker and CI templates so that publishing and verifying contracts is a few lines in each pipeline, and provider deployments that would break a verified consumer contract are blocked with can-i-deploy style checks. Messaging contracts for Kafka or other brokers are included from the start, not only HTTP, and the teams agree on versioning and deprecation rules so that changes have a safe path instead of a blocked one.

Why this question is asked

Two teams breaking each other's APIs despite integration environments is a sign that the environments catch problems too late and too vaguely. By the time a shared environment shows the failure, both changes are merged, several other teams have deployed, and the argument is about whose fault it is. Contract testing moves the check into each team's own pipeline, but introducing it across 40 services is an organisational change as much as a technical one. Interviewers ask this scenario to see whether we can roll out a practice, not just name it. In this answer, we will choose where to start, set up the shared infrastructure, add the deployment gate, extend contracts to messaging, agree how APIs change, and plan the wider rollout.

1Start Where It Breaks Most

Rolling contract testing out to 40 services at once spreads attention thinly and produces many half-finished setups. I would start with evidence: incident reports, failed deployments and integration environment failures from the last few months, grouped by which pair of services was involved. Usually a few interfaces account for most of the breakages, such as the two teams in the question and perhaps three or four other pairs.

Those pairs become the pilot. They have the strongest motivation, because they feel the pain, and success there is visible to everyone. The pilot also tests our templates and documentation on real code before other teams depend on them. A good pilot result, such as 'no breakages between orders and customers in the eight weeks since contracts', is the best argument for the rest of the rollout.

2A Broker and CI Templates

Contracts need a shared home. A contract broker, such as a Pact Broker or a hosted equivalent, stores every consumer's contracts by version and records which provider versions have verified them. If the organisation chooses Spring Cloud Contract with stubs in a Maven repository, the repository and the provider's contract folder play a similar role, and Spring Cloud Contract can also publish to a Pact Broker.

The platform team then makes the workflow cheap with CI templates. A consumer pipeline step publishes contracts after its tests pass, tagged with the git commit and branch. A provider pipeline step fetches the contracts it must satisfy and verifies them. The broker can call a webhook when a consumer publishes a changed contract, so the provider's verification runs at once and the consumer learns within minutes whether its new expectation is supported. Each team adds a few lines to its pipeline instead of designing this from scratch.

Java
# Consumer pipeline, after the contract tests pass (Pact CLI shown; check your tool's syntax)
pact-broker publish build/pacts --consumer-app-version "$GIT_SHA" --branch "$GIT_BRANCH"
# Provider pipeline: verification runs as part of the test stage, results published with the version
# Before deploying any service to an environment
pact-broker can-i-deploy --pacticipant order-service --version "$GIT_SHA" --to-environment production
# after a successful deployment
pact-broker record-deployment --pacticipant order-service --version "$GIT_SHA" --environment production

3Block Deployments That Break Verified Contracts

The deployment gate is what turns contracts from documentation into protection. Before a service is deployed to an environment, the pipeline asks the broker whether this version is compatible with the versions of its consumers and providers currently deployed there. For a provider, that means it has verified every contract of every consumer version in that environment. For a consumer, it means the deployed provider version has verified this consumer's contract. If not, the deployment stops, with a message naming the incompatible partner.

Two details make the gate workable. New contracts from consumers should not immediately block a provider that has not had a chance to implement them; Pact calls this the pending pacts feature, where a new, never-verified contract shows failures without failing the provider's build. And the broker must know what is deployed where, which is why each pipeline records deployments. With those in place, the gate blocks real breaking changes and little else.

Step throughA provider deployment with a contract gate
  1. Provider change mergedFor example, rename fullName to displayName
  2. Verify all consumer contracts from the brokerContracts of consumer versions in each environment
  3. Publish verification resultsTagged with the provider version
  4. can-i-deploy to production?
    YesDeploy and record the deploymentNoStop: names the consumer that would break
  5. Provider and consumer agree a changeAdd the new field, migrate consumer, remove old field later

5 steps in order. Play them, or step through them one at a time.

4Include Messaging, Not Only HTTP

Many of the breakages between services are not in HTTP calls but in events: a producer renames a field in an OrderPlaced event, changes a timestamp format, or changes the key, and consumers on Kafka fail or, worse, silently skip messages. These break just as often and are harder to see, because there is no error response.

Both Pact and Spring Cloud Contract support message contracts. The consumer describes the message it expects to receive on a topic, and the producer's build verifies that its code produces a matching message. If the organisation uses a schema registry with Avro or Protobuf, its compatibility checks cover the format of events, and contract tests then add which fields consumers actually depend on. I would include at least the most important event streams in the pilot, so messaging is not an afterthought.

5Agree How APIs Change

Contracts make breaking changes visible; they do not make them unnecessary. Without agreed rules, a provider that wants to rename a field is simply blocked, and frustration with the tool grows. So the teams agree on a few rules for evolving APIs. Additive changes, such as new optional fields or new endpoints, are always allowed. Consumers read tolerantly, ignoring fields they do not know. A breaking change follows an expand and contract pattern: add the new field alongside the old one, let consumers move to it and update their contracts, and remove the old field only when the broker shows that no deployed consumer version still uses it.

For changes that cannot be done that way, versioning rules apply, such as a new major version of the endpoint or event type, with a deprecation period that is announced and tracked. The broker's data makes this concrete: it can show which consumers still depend on the old field, so deprecation becomes a list of teams to talk to rather than a guess.

6Rolling Out Beyond the Pilot

After the pilot, the rollout follows the dependency graph and the pain. Services with many consumers, which are the ones whose changes break the most, come next, followed by their consumers. Each team gets the templates, a short guide written by the pilot teams, and someone from the platform or pilot teams to pair with for the first contract. Progress is tracked by interfaces covered, not services, because what matters is the connections.

I would measure the outcome with the same data that started it: integration breakages and failed deployments between services, and the time teams spend in the integration environment. As coverage grows, the integration environment can shrink to a small smoke suite, which is often the change teams appreciate most.

7Follow-up questions

What if consumers write contracts that are too strict?

Strict contracts, with exact values or fields the consumer does not use, block providers for no reason. The guide and reviews should push for type matchers and only the fields actually read. Since the provider sees a failing contract with the consumer's name, the two teams can quickly agree to loosen it.

Do you still need the integration environments?

Fewer of them and for less. A small smoke suite in a deployed environment still checks real wiring, configuration and security between services. But it no longer has to catch interface breakages, so it can be short and stable.

How do you handle third-party APIs that will not run your contracts?

We cannot make an external provider verify our contracts, so we test our client against stubs built from their documentation or recorded traffic, and add a small scheduled test against their sandbox to detect changes. Contract testing is for the interfaces we control on both sides.

8Conclusion

In this answer, we introduced contract testing across 40 services by starting with the interfaces that break most often and using a pilot to prove the approach. A contract broker and CI templates make publishing and verifying contracts cheap, and can-i-deploy style checks block deployments that would break verified consumer contracts, with pending contracts keeping new expectations from blocking providers unfairly. Messaging contracts are part of the scope from the start, and agreed versioning and deprecation rules, such as expand and contract, give teams a safe way to change APIs.

What to say in the interviewAbout 90 seconds aloud

Open with

I wouldn't start with all 40 services. I'd look at incidents and failed deployments, find the pairs of services that break each other most, including the two teams in question, and pilot there.

Then, if they want more

Next, the platform provides the infrastructure: a contract broker, like a Pact Broker, that stores contracts per consumer version and records verifications, plus CI templates so consumers publish contracts tagged with the commit and providers verify them in their normal test stage. A webhook triggers provider verification when a consumer changes a contract, so feedback comes in minutes.

The key part is the gate: before any deployment, the pipeline runs a can-i-deploy check against the broker for the target environment, so a provider can't deploy a version that breaks a consumer version running there, and each deployment is recorded. I'd enable pending contracts so a brand-new consumer expectation doesn't block a provider immediately.

I'd include messaging from the start, because event changes on Kafka break consumers just as often and more silently; both Pact and Spring Cloud Contract support message contracts.

And we need rules for changing APIs: additive changes are fine, consumers read tolerantly, breaking changes go through expand and contract, adding the new field, migrating consumers, and removing the old one only when the broker shows nobody uses it.

After the pilot, I'd roll out to the providers with the most consumers, track coverage by interface, and measure integration breakages.

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 "Two teams keep breaking each other's APIs despite integration environments. How would...": https://scrivio-interview-library.netlify.app/java/test-strategy/3145ac6ee5/