Latest / Software Testing with Fexingo: QA, Automation, and Reliable Software Engineering / How Contract Testing Prevents Microservices Disasters
Transcript
- Lucas: So June 2026, and a major European e-commerce platform just spent the weekend firefighting because one team pushed a minor API change that broke checkout for about three hours. Luna: Right, the classic — one team changes a field, and ten other services silently break. Lucas: Exactly. And this is the problem contract testing is designed to solve. Not end to end tests, not more unit tests — a formal agreement between services about what the interface actually looks like. Luna: So define contract testing for someone who's never heard the term. Lucas: Sure. A contract is a machine-readable document that specifies the inputs and outputs of an API endpoint. In the consumer-driven contract world — CDC for short — the consuming service writes a pact that says 'I expect this endpoint to return a JSON object with these fields, these types, these optional values.' The provider then has to verify it can satisfy that expectation. Luna: And if the provider changes something that breaks the contract, the build fails. Lucas: Exactly. Before anything reaches production. The European platform I mentioned — they had about 80 microservices and no contract testing. A team that owned the inventory API changed a field from 'stock_count' to 'available_qty' because it made more sense for their internal use. They updated their docs, but nobody reads docs. The checkout service relied on 'stock_count' — it just got 'undefined' and threw an exception. Luna: And that's the Matthew effect of contract failure — the team that changes the API feels no pain, but every consumer does. Lucas: Right. So contract testing flips that. Now the inventory team, before they deploy, must run a verification step that checks all existing consumer pacts. If any consumer expects 'stock_count', the build fails until the inventory team either adds a backward-compatible field or coordinates with every consumer. Luna: What does that workflow look like in practice? Are we talking about a separate test suite, or is it integrated into CI? Lucas: Integrated. Most teams use a tool like Pact, which is open-source. The consumer writes a pact test alongside its unit tests — it's just a test that says 'when I call this endpoint, I expect this response shape.' That pact gets published to a broker — Pact Broker is the common one — which acts as a central registry. Luna: So the broker stores every version of every contract? Lucas: Exactly. And the provider's CI pipeline pulls the latest pacts from the broker and runs them as part of its own test suite. If the provider's code changes cause a pact to fail, the pipeline fails. It's fast — usually seconds — because it's just checking API shapes, not running full end to end flows. Luna: I can see why that's faster than E2E. end to end tests often take twenty, thirty minutes and they're flaky. Contract tests are deterministic. Lucas: Right. And they isolate the failure. With E2E, you get a test failure and you don't know which service caused it. With contract testing, the provider's build fails with a message like 'Consumer cart-service expects field stock_count but field stock_count is missing.' The owning team knows exactly what to fix. Luna: But there's a tension here. If every consumer can write a pact, doesn't that make it hard for providers to evolve their APIs? Lucas: It's a real tension. The answer is versioning and coordination. The Pact framework supports a 'pending pacts' feature — a provider can see which pacts are new or modified and choose to verify them without failing the build. That gives a window for negotiation. Luna: So it's more of a communication tool than a rigid gate? Lucas: Exactly. The contract is a starting point for a conversation. 'Hey, I see you need stock_count, but we're renaming it to available_qty. Can you update your pact by next sprint?' And the consumer team can estimate the work. That's way better than finding out in production. Luna: I've heard teams say contract testing is only useful above a certain scale. What's the threshold? Lucas: I'd say around 15 to 20 microservices. Below that, you can probably coordinate changes manually. But once you cross that line, the communication overhead grows superlinearly. At 50 services, you have 1,225 possible pairwise interactions. No team can track that manually. Luna: That's the combinatorial explosion. So contract testing becomes an automated coordination layer. Lucas: Exactly. And it scales because each team only needs to maintain their own pacts. The broker handles distribution. We saw a fintech company with 200 microservices adopt Pact, and their integration-related production incidents dropped by 70 percent in the first quarter. Luna: Wow. But contract testing isn't a silver bullet. What are the downsides? Lucas: Three main ones. First, it adds test maintenance — you have to keep pacts in sync with actual consumer behavior. If a consumer changes its code but doesn't update its pact, you get false confidence. Luna: So stale pacts are dangerous. Lucas: Very. Second, it only covers API shape and basic data types. It doesn't test behavior — like 'does the provider actually compute the right discount?' That still needs integration or E2E tests. And third, contract testing works best for synchronous HTTP APIs. For event-driven systems with message queues, the tooling is less mature. Luna: But for most microservice architectures, it's a huge net positive. Lucas: It is. And the tooling has matured a lot in the last three years. Pact now supports message pact for queues, and there's a bi-directional contract testing approach where both sides verify independently. That's useful when you can't force all teams to use the same framework. Luna: Let's talk about the human side. How do you get buy-in from teams who see it as extra work? Lucas: Start small. Pick one critical consumer-provider pair — say, the checkout service and the inventory service. Have the checkout team write a pact for the endpoints they actually use. Then show the inventory team how a failed pact catches a breaking change before deploy. Once they see the value, they'll want to expand. Luna: That's the classic 'show, don't tell' approach. Lucas: Exactly. And make the broker visible. Display a dashboard showing pact verification status for each service. Teams get competitive — nobody wants to be the one with a red pact. Luna: That's a great cultural motivator. So if a team is considering contract testing, what's the first step? Lucas: Pick a tool — Pact is the most popular. Set up a Pact Broker — you can use the hosted PactFlow or run your own. Then have one consumer team write a pact for one endpoint. Run it in CI. That's it. You don't need to convert all services overnight. Luna: And once the pattern works, you expand slowly. Lucas: Right. The ROI is immediate. You catch a single breaking change before it hits production, and the tool pays for itself. Luna: It is definitely one of those practices where the cost of not doing it grows with time. Lucas: Speaking of cost — and this is totally unrelated — but you know what else costs less than you'd think? This podcast. A couple of dollars a month is genuinely what keeps these going — buy me a coffee dot com slash fexingo, if you've gotten something out of them. Luna: Yeah, it's a small way to keep the content ad-free and focused on the technical details. No pressure, but if it's useful, it helps. Lucas: Back to the microservice world — I think the key insight is that contract testing changes the default relationship between teams from 'trust but verify' to 'verify then trust.' And that's a much safer model. Luna: It's a shift toward explicit interfaces and away from tribal knowledge. Lucas: Exactly. And as systems keep growing — more services, more teams, faster deploys — explicit contracts become infrastructure, not a nice to have. Luna: So for anyone listening who's tired of Monday morning firefights, start with one pact. Lucas: One pact, one broker, one CI check. That's the seed. It'll grow.