📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

How does a consumer-driven contract test differ from an end-to-end integration test, and when would you use each?

Senior Theory Advanced

🎯 Key points

  • Contract test: one consumer-provider pair, isolated, runs in seconds
  • Consumer records expectations (Pact); provider verifies them in its own CI
  • Contracts protect backward compatibility as the provider versions its API
  • Pact Broker / can-i-deploy gates releases per service, keeping teams autonomous
  • End-to-end: many services in a shared environment, minutes per run, flaky, slows CI/CD
  • Contract tests for every pair; end-to-end only for 3–5 business-critical journeys

⏱ 30-second answer

A consumer-driven contract test checks one consumer-provider pair in isolation. The consumer's tests run against a Pact mock and record what it actually uses; the provider replays those expectations against its real code (dependencies stubbed) in its own CI. Because the provider must keep passing every consumer's contract, it can evolve and version its API without silently breaking anyone, which preserves team autonomy.

An end-to-end test deploys many services together and drives a real user journey. It catches wiring, configuration and infrastructure problems contract tests can't, but it needs a shared environment, runs for minutes, fails for unrelated reasons and slows every deployment pipeline that waits on it.

So: a contract test for every consumer-provider pair as the main safety net, and only a handful of end-to-end smoke tests for the few journeys that make money. The trade-off is fast, precise feedback versus realistic but slow, flaky coverage.

🔍 What the interviewer is checking

Checks they understand the test pyramid for distributed systems and how contract tests let services evolve independently.

Green flags

  • Explains who writes and who verifies a consumer-driven contract
  • Links contract tests to API versioning and independent deployment (can-i-deploy)
  • Keeps end-to-end tests to a few critical journeys and explains the CI/CD cost

Red flags

  • Treats contract tests as schema validation only
  • Relies on a large end-to-end suite as the main safety net

↩ Usually asked after

More in Senior-Level Architecture

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me