Contract testing between services

Testing backends Mid-level Python 3.13+ PostgreSQL 17+ Reviewed By Best Latest Apps

Order the steps

Order a consumer-driven contract check.

  • A failed check blocks the provider's deploy
  • Provider CI replays every contract against the real provider
  • The contract is published to a broker
  • Consumer tests record the requests and fields they rely on

Choose an answer, then open Show answer below to check it.

Show answer

Answer: D C B A

  1. Consumer tests record the requests and fields they rely on This produces the contract.
  2. The contract is published to a broker Versioned by consumer.
  3. Provider CI replays every contract against the real provider Using provider states for data.
  4. A failed check blocks the provider's deploy Before anything breaks.

30-second answer

Write down the contract and test both sides against it. In consumer-driven contract testing (Pact), each consumer records the requests it makes and the response fields it relies on; the provider's CI replays those against the real provider and fails if it would break any consumer. Schema-first alternatives check an OpenAPI or protobuf schema for breaking changes on every pull request. Both catch breakage before deploy, quickly.

Practise saying it · 30 s. No recording, just a timer

Contract testing.

Say your answer out loud, then check which of these points you covered:

  • Contract between services
  • Consumer-driven (Pact)
  • Provider verifies in CI
  • Schema diffs
  • Few E2E

Deep dive

A broker stores contracts and tells you whether a version is safe to deploy.

Protobuf/gRPC tooling (buf breaking) detects removed fields and changed numbers.

Contracts cover shape and semantics you rely on, not every field.

Still keep a few end-to-end smoke tests.

Common mistakes

  • Relying on a shared staging environment to find breakage.
  • Contracts that assert every field, so any change fails.
  • Testing only the consumer against a mock that never meets the provider.

Senior take & follow-ups

The problem, consumer-driven contracts, schema diffing, and where E2E still fits.

Follow-up questions

Think of your answer first, then open the hint.

  1. Consumer-driven or schema-first?

    Show hint

    Consumer-driven captures real usage; schema-first is simpler for public APIs.

  2. What does 'can I deploy' check?

    Show hint

    That the version is verified against every consumer's contract in that environment.

Suggest a fix if something here is wrong or out of date.