Video in progress
How do you wire contract tests into the CI/CD process so that a provider can't deploy a version that breaks a consumer?
Contracts are stored in the broker with the consumer version and environment; the provider verifies them in every build and writes the result to the broker; and in the deploy pipeline each side asks can-i-deploy "am I compatible with my partners in this environment?". After a deploy, the environment is recorded in the broker.
📖 Answer
Just writing a contract isn't enough: if it doesn't block the deploy decision, it's only half useful.
The flow (in Pact Broker / PactFlow terms):
- Consumer CI: the tests generate the contract →
publishto the broker (version = git SHA, with the branch name). - A broker webhook triggers the provider's verification job, so the provider learns right away that a consumer changed.
- Provider CI: it fetches the contracts of "the consumer versions in prod and on main" (consumer version selectors), verifies them against the real code, and writes the result to the broker.
- The deploy job on both sides:
pact-broker can-i-deploy --pacticipant order-service --version $SHA --to-environment production. If the answer is "no", the deploy stops. - If the deploy succeeds:
record-deployment, so the broker now knows which version is in prod.
The organizational parts are harder than the technical part:
- The procedure for adding a new field. The consumer publishes a contract that expects a new field, the provider doesn't supply it yet, and the consumer can't deploy. That's correct behavior, but teams complain "why are we blocked". You need to explain it, and set up "pending pacts" (a new contract doesn't immediately fail the provider's build).
- Old consumer versions. If there are long-lived consumers like a mobile app, the provider has to support several old versions, so state that explicitly in the selectors.
- Asynchronous contracts. There are message pacts for Kafka messages too; I often use them together with the compatibility check in Schema Registry.
I roll it out not to everyone at once but starting with the 2-3 integrations that caused the most incidents. Once the results show, other teams ask for it themselves.
Sign up to mark studied questions and save your progress.