0
0
Microservicessystem_design~12 mins

Contract testing (Pact) in Microservices - Architecture Diagram

Choose your learning style9 modes available
System Overview - Contract testing (Pact)

This system uses contract testing with Pact to ensure that microservices communicate correctly. It verifies that the service provider meets the expectations defined by the service consumer before deployment, reducing integration errors.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  +-------------------+
  |                   |
Consumer Service   Provider Service
  |                   |
  v                   v
Consumer Pact Mock  Provider Pact Verifier
  |                   |
  +---------+---------+
            |
            v
       Pact Broker
            |
            v
       CI/CD Pipeline
Components
User
user
Initiates requests to the system
Load Balancer
load_balancer
Distributes incoming requests evenly to API Gateway instances
API Gateway
api_gateway
Routes requests to appropriate microservices
Consumer Service
service
Microservice that consumes APIs from Provider Service
Provider Service
service
Microservice that provides APIs to Consumer Service
Consumer Pact Mock
mock_service
Simulates Provider Service behavior for Consumer tests
Provider Pact Verifier
verifier
Verifies Provider Service meets Consumer's contract
Pact Broker
broker
Stores and shares contracts between Consumer and Provider
CI/CD Pipeline
pipeline
Automates contract testing and deployment
Request Flow - 14 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayConsumer Service
Consumer ServiceProvider Service
Provider ServiceConsumer Service
Consumer ServiceAPI Gateway
API GatewayLoad Balancer
Load BalancerUser
Consumer ServiceConsumer Pact Mock
Provider Pact VerifierProvider Service
Consumer Pact MockPact Broker
Provider Pact VerifierPact Broker
CI/CD PipelineConsumer Pact Mock
CI/CD PipelineProvider Pact Verifier
Failure Scenario
Component Fails:Pact Broker
Impact:Contracts cannot be shared or fetched, blocking contract testing and deployments
Mitigation:Use broker replication and backups; fallback to cached contracts in CI/CD pipeline
Architecture Quiz - 3 Questions
Test your understanding
Which component stores and shares the contracts between services?
APact Broker
BAPI Gateway
CLoad Balancer
DConsumer Pact Mock
Design Principle
This architecture ensures microservices communicate reliably by verifying contracts before deployment. It uses a broker to share contracts and mocks/verifiers to test both sides independently, reducing integration errors and improving deployment confidence.