What is consumer-driven contract testing with Pact?

Answer

Consumer-driven contract testing with Pact is a testing strategy that verifies service-to-service compatibility without requiring live integration environments. The consumer service defines a contract — a specification of the requests it makes and the responses it expects — and Pact generates a mock provider for the consumer's tests. The contract is published to a Pact Broker. The provider service's CI pipeline then verifies it can satisfy all published contracts by replaying the specified requests against its real code. If the provider changes its API in a way that breaks a consumer's contract, the CI pipeline fails before deployment. This gives teams confidence they can deploy services independently without running expensive full-stack integration tests, while still catching breaking API changes early — essential for teams operating hundreds of microservices.