SlideShare a Scribd company logo
1 of 84
Download to read offline
COLLABORATING WITH
CONTRACTS
@stania_ang
REAL LIFE: COLLABORATION
REAL LIFE: COLLABORATION
• just do it
REAL LIFE: COLLABORATION
• just do it
• negotiate a contract, adhere to it
REAL LIFE: CONTRACTS
Provider
Ice cream supplier
Consumer
Supermarket
Contract
must order 1 week in advance
must pay at time of order
must deliver within 3 business days
product must not expire within 2 months
MOVING ALONG...
COLLABORATION: SERVICES
SERVICE
SERVICE
• a reusable software component encapsulating a business
function
SERVICE
• a reusable software component encapsulating a business
function
• can be exposed over HTTP, queue, ...
ProviderConsumer
SERVICE CONTRACTS
SERVICE CONTRACTS
• request - response
SERVICE CONTRACTS
• request - response
• performance characteristics
PERSON SERVICE
ProviderConsumers
A
B
{
id: 1,
name: “Jane”,
age: 26
}
USE CASES
CASE 1
PERSON SERVICE
ProviderConsumers
A
B
{
id: 1,
name: “Jane”,
age: 26
}
{
id: 1,
name: “Jane”,
age: 26
}
{
id: 1,
name: “Jane”,
age: 26
}
NEW CONSUMER, NEWTROUBLE
Provider
Consumers
A
B
{
id: 1,
name: “Jane”,
age: 26
}
{
id: 1,
name: “Jane”,
age: 26
}
{
id: 1,
name: “Jane”,
age: 26
}
C
{
id: 1,
first_name: “Jane”,
last_name: “Good”,
age: 26
}
UPDATE PROVIDER DIRECTLY
Provider
Consumers
A
B
{
id: 1,
first_name: “Jane”,
last_name: “Good”,
age: 26
}
{
id: 1,
name: “Jane”,
age: 26
}
{
id: 1,
name: “Jane”,
age: 26
}
C
{
id: 1,
first_name: “Jane”,
last_name: “Good”,
age: 26
}
CONSUMERS A AND B BREAKS
Provider
Consumers
A
B
{
id: 1,
first_name: “Jane”,
last_name: “Good”,
age: 26
}
{
id: 1,
name: “Jane”,
age: 26
}
{
id: 1,
name: “Jane”,
age: 26
}
C
{
id: 1,
first_name: “Jane”,
last_name: “Good”,
age: 26
}
CONSUMER-DRIVEN
CONTRACTS
Provider
Consumers
A
B
C
Contract A
Contract B
Contract C
{
id: 1,
name: “Jane”,
age: 26
}
{
id: 1,
name: “Jane”,
age: 26
}
{
id: 1,
first_name: “Jane”,
last_name: “Good”,
age: 26
}
WHY ISTHIS USEFUL?
WHY ISTHIS USEFUL?
• services are only useful when they are used
WHY ISTHIS USEFUL?
• services are only useful when they are used
• consumer-driven contracts makes consumer expectations
explicit
CONSUMER-DRIVEN
CONTRACTTESTS
CONSUMER-DRIVEN
CONTRACTTESTS
all the goodness of consumer-driven contracts and more
rake consumer:verify
rake provider:verify
executable
can be run as part of build pipeline
unit contract functional deploy
living documentation
AN EXAMPLE
Provider
Consumers
A
B
{
id: 1,
first_name: “Jane”,
last_name: “Good”,
age: 26,
friends: ...
}
{
id: 1,
name: “Jane”,
age: 26
}
{
id: 1,
name: “Jane”,
age: 26
}
C
{
id: 1,
first_name: “Jane”,
last_name: “Good”,
age: 26
}
$$$$
“Let me go through the 20-page contract to see if
they mention ‘friends’...”
PLAYS WELL WITHTDD
PLAYS WELL WITHTDD
• write consumer-driven contract test for consumer C
PLAYS WELL WITHTDD
• write consumer-driven contract test for consumer C
• red-green-refactor: consumer side
PLAYS WELL WITHTDD
• write consumer-driven contract test for consumer C
• red-green-refactor: consumer side
• red-green-refactor: provider side
PLAYS WELL WITHTDD
• write consumer-driven contract test for consumer C
• red-green-refactor: consumer side
• red-green-refactor: provider side
• make sure consumer-driven contract tests for consumers A and
B still passes too
MAKING CONSUMER
EXPECTATIONS EXPLICIT
CASE 2
ProviderConsumer
Service
Boundary
Provider stub
testing around service boundary
{
id: 1,
name: “Jane”,
age: 26
}
ProviderConsumer
Service
Boundary
Provider stub
unit test on consumer:
uses a provider stub
verifies the consumer processes the stubbed response
properly
{
id: 1,
name: “Jane”,
age: 26
}
ProviderConsumer
Service
Boundary
unit test on provider:
use fake consumer
tests that given the right request,
it returns the right response
Fake consumer
ProviderConsumer
Service
Boundary
Provider stub
there could be a mismatch
{
id: 1,
name: “Jane”,
age: 26,
address: ...
}
Fake consumer
{
id: 1,
name: “Jane”,
age: 26
}
ProviderConsumer
Service
Boundary
Provider stub
unit tests pass, but app will blow up
{
id: 1,
name: “Jane”,
age: 26,
address: ...
}
Fake consumer
{
id: 1,
name: “Jane”,
age: 26
}
HOW CAN CONTRACTTESTS
HELP?
ProviderConsumer
Service
Boundary
Provider stub
both sides are verified against the same contract
{
id: 1,
name: “Jane”,
age: 26,
address: ...
}
Fake consumer
{
id: 1,
name: “Jane”,
age: 26
}
Contract
ProviderConsumer
Service
Boundary
Provider stub
write expectations from the consumer side
{
id: 1,
name: “Jane”,
age: 26,
address: ...
}
Fake consumer
{
id: 1,
name: “Jane”,
age: 26
}
Contract
ProviderConsumer
Service
Boundary
Provider stub
generate the contract
{
id: 1,
name: “Jane”,
age: 26,
address: ...
}
Fake consumer
{
id: 1,
name: “Jane”,
age: 26
}
Contract
ProviderConsumer
Service
Boundary
Provider stub
verify that the provider adheres to the same contract
{
id: 1,
name: “Jane”,
age: 26,
address: ...
}
Fake consumer
{
id: 1,
name: “Jane”,
age: 26
}
Contract
fail:
address is missing!
MAKING SURE PROVIDER AND
CONSUMER DOTHEIR JOB
CASE 3
another teamour team
a tale of 2 apps
another teamour team
in the beginning was nothing
another teamour team
Service
Boundary
Contract
another teamour team
Service
Boundary
Contractexecutable
ProviderConsumer
Service
Boundary
Provider stub
consumer sends the right request
{
id: 1,
name: “Jane”,
age: 26
}
Fake consumer
{
id: 1,
name: “Jane”,
age: 26
}
Contract
ProviderConsumer
Service
Boundary
Provider stub
provider returns the right response
{
id: 1,
name: “Jane”,
age: 26
}
Fake consumer
{
id: 1,
name: “Jane”,
age: 26
}
Contract
another teamour team
Service
Boundary
Contract
this enables parallel development
ENABLING PARALLEL
DEVELOPMENT
TOOL: PACT
github.com/realestate-com-au/pact
ProviderConsumer
Service
Boundary
Provider stub
{
id: 1,
name: “Jane”,
age: 26
}
Fake consumer
{
id: 1,
name: “Jane”,
age: 26
}
ProviderConsumer
Service
Boundary
Provider stub
write the tests for the consumer
{
id: 1,
name: “Jane”,
age: 26
}
Fake consumer
{
id: 1,
name: “Jane”,
age: 26
}
person_service.
given("a person with too many friends").
upon_receiving("request for person details").
with(method: :get,
path: "/person/1",
query: '').
person_service.
given("a person with too many friends").
upon_receiving("request for person details").
with(method: :get,
path: "/person/1",
query: '').
person_service.
given("a person with too many friends").
upon_receiving("request for person details").
will_respond_with(status: 200,
headers: {'Content-Type' => 'application/json;
charset=utf-8'},
body: {
id: 1,
name: “Jane”,
age: 26,
address: ...
})
with(method: :get,
path: "/person/1",
query: '').
person_service.
given("a person with too many friends").
upon_receiving("request for person details").
will_respond_with(status: 200,
headers: {'Content-Type' => 'application/json;
charset=utf-8'},
body: {
id: 1,
name: “Jane”,
age: 26,
address: ...
})
expect(subject.person_details(“1”)).to eq(expected_person)
ProviderConsumer
Service
Boundary
Provider stub
run
watch it fail
make it pass
{
id: 1,
name: “Jane”,
age: 26
}
Fake consumer
{
id: 1,
name: “Jane”,
age: 26
}
ProviderConsumer
Service
Boundary
Provider stub
the consumer tests generates a “pact”
{
id: 1,
name: “Jane”,
age: 26
}
Fake consumer
{
id: 1,
name: “Jane”,
age: 26
}
Pact
ProviderConsumer
Service
Boundary
Provider stub
configure to verify selected pact(s)
{
id: 1,
name: “Jane”,
age: 26
}
Fake consumer
{
id: 1,
name: “Jane”,
age: 26
}
Pact
Provider
rake pact:verify
Pact
controller
serializer
service
model
actual HTTP requests
Fake consumer
MORE ON PACT
standalone stub
Out-of-process
provider stub
{
id: 1,
name: “Jane”,
age: 26
}
Actual
consumer
person_service.
given("a person with too many friends").
upon_receiving("request for person details").
provider states
given("a person with too many friends").
person_service.
given("a person with too many friends").
upon_receiving("request for person details").
provider states
provider_state "a person with too many friends" do
set_up do
10_000.times do
person = Person.first
person.friends << Person.new(...)
end
end
end
will_respond_with(status: 200,
headers: {'Content-Type' => 'application/json;
charset=utf-8'},
body: {
id: 1,
name: Pact::SomethingLike.new(“Jane”),
age: 26,
address: ...
})
loose matching
with(method: :get,
path: "/person/1",
query: '').
person_service.
given("a person with too many friends").
upon_receiving("request for person details").
Pact::SomethingLike.new(“Jane”)
SUMMING UP
USE CASES
USE CASES
• making consumer expectations explicit
USE CASES
• making consumer expectations explicit
• making sure both consumer and provider do their job
USE CASES
• making consumer expectations explicit
• making sure both consumer and provider do their job
• enabling parallel development
THE DEVIL IS INTHE DETAILS
YMMV
SEE COLLABORATION?
THINK CONTRACTS
THANKYOU

More Related Content

Similar to Collaborating with Contracts

Architectural Considerations For Complex Mobile And Web Applications
Architectural Considerations For Complex Mobile And Web ApplicationsArchitectural Considerations For Complex Mobile And Web Applications
Architectural Considerations For Complex Mobile And Web Applications
Vivek Jain
 

Similar to Collaborating with Contracts (20)

Consumer-Driven Contract Testing - Workshop - January 2021
Consumer-Driven Contract Testing - Workshop - January 2021Consumer-Driven Contract Testing - Workshop - January 2021
Consumer-Driven Contract Testing - Workshop - January 2021
 
The case for consumer-driven contracts
The case for consumer-driven contractsThe case for consumer-driven contracts
The case for consumer-driven contracts
 
Consumer-driven contracts with Pact and PHP
Consumer-driven contracts with Pact and PHPConsumer-driven contracts with Pact and PHP
Consumer-driven contracts with Pact and PHP
 
Consumer Driven Contracts - A Deep Dive
Consumer Driven Contracts - A Deep DiveConsumer Driven Contracts - A Deep Dive
Consumer Driven Contracts - A Deep Dive
 
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
 
vodQA(Pune) 2018 - Consumer driven contract testing using pact
vodQA(Pune) 2018 - Consumer driven contract testing using pactvodQA(Pune) 2018 - Consumer driven contract testing using pact
vodQA(Pune) 2018 - Consumer driven contract testing using pact
 
Measuring Integration Service Quality Gap in A Service System Network
Measuring Integration Service Quality Gap in A Service System NetworkMeasuring Integration Service Quality Gap in A Service System Network
Measuring Integration Service Quality Gap in A Service System Network
 
Mastering the api hell
Mastering the api hellMastering the api hell
Mastering the api hell
 
Consumer Driven Contracts (DDD Perth 2016)
Consumer Driven Contracts (DDD Perth 2016)Consumer Driven Contracts (DDD Perth 2016)
Consumer Driven Contracts (DDD Perth 2016)
 
How to analyze a Performance issue
How to analyze a Performance issueHow to analyze a Performance issue
How to analyze a Performance issue
 
Consumer Driven Contract.pdf
Consumer Driven Contract.pdfConsumer Driven Contract.pdf
Consumer Driven Contract.pdf
 
Move fast and consumer driven contract test things
Move fast and consumer driven contract test thingsMove fast and consumer driven contract test things
Move fast and consumer driven contract test things
 
MongoDB World 2019: How Braze uses the MongoDB Aggregation Pipeline for Lean,...
MongoDB World 2019: How Braze uses the MongoDB Aggregation Pipeline for Lean,...MongoDB World 2019: How Braze uses the MongoDB Aggregation Pipeline for Lean,...
MongoDB World 2019: How Braze uses the MongoDB Aggregation Pipeline for Lean,...
 
CDC Tests - Integration Tests cant be made simpler than this!
CDC Tests - Integration Tests cant be made simpler than this!CDC Tests - Integration Tests cant be made simpler than this!
CDC Tests - Integration Tests cant be made simpler than this!
 
INFORMS 2014 - The Integration Quality Gap in Service System Networks
INFORMS 2014 - The Integration Quality Gap in Service System NetworksINFORMS 2014 - The Integration Quality Gap in Service System Networks
INFORMS 2014 - The Integration Quality Gap in Service System Networks
 
23 social and digital services agencies should offer
23 social and digital services agencies should offer23 social and digital services agencies should offer
23 social and digital services agencies should offer
 
The 23 Social and Digital Services Your Agency Should Be Selling, But Probabl...
The 23 Social and Digital Services Your Agency Should Be Selling, But Probabl...The 23 Social and Digital Services Your Agency Should Be Selling, But Probabl...
The 23 Social and Digital Services Your Agency Should Be Selling, But Probabl...
 
Agile Contracts
Agile ContractsAgile Contracts
Agile Contracts
 
HandyMan(SRS Final Presentation)
HandyMan(SRS Final Presentation)HandyMan(SRS Final Presentation)
HandyMan(SRS Final Presentation)
 
Architectural Considerations For Complex Mobile And Web Applications
Architectural Considerations For Complex Mobile And Web ApplicationsArchitectural Considerations For Complex Mobile And Web Applications
Architectural Considerations For Complex Mobile And Web Applications
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

Collaborating with Contracts