SlideShare a Scribd company logo
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 (20)

PDF
Consumer-Driven Contract Testing - Workshop - January 2021
Paulo Clavijo
 
PDF
The case for consumer-driven contracts
DiUS
 
PPTX
Consumer-driven contracts with Pact and PHP
Andy Kelk
 
PPTX
Consumer Driven Contracts - A Deep Dive
Ramya Authappan
 
PPTX
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
Agile Testing Alliance
 
PPTX
vodQA(Pune) 2018 - Consumer driven contract testing using pact
vodQA
 
PPTX
Measuring Integration Service Quality Gap in A Service System Network
Stephen Kwan
 
PDF
Mastering the api hell
Florian Pfleiderer
 
PDF
Consumer Driven Contracts (DDD Perth 2016)
Rob Crowley
 
PPTX
How to analyze a Performance issue
Fabien Raynaud
 
PDF
Consumer Driven Contract.pdf
Danylenko Max
 
PDF
Move fast and consumer driven contract test things
Alon Pe'er
 
PDF
MongoDB World 2019: How Braze uses the MongoDB Aggregation Pipeline for Lean,...
MongoDB
 
PDF
CDC Tests - Integration Tests cant be made simpler than this!
Ramya Authappan
 
PPTX
INFORMS 2014 - The Integration Quality Gap in Service System Networks
Stephen Kwan
 
PPT
The 23 Social and Digital Services Your Agency Should Be Selling, But Probabl...
agencyside
 
PPT
23 social and digital services agencies should offer
BOLO Conference
 
PPTX
Agile Contracts
Johannes Brodwall
 
PPTX
HandyMan(SRS Final Presentation)
FazleRabbi80
 
PDF
Architectural Considerations For Complex Mobile And Web Applications
IndicThreads
 
Consumer-Driven Contract Testing - Workshop - January 2021
Paulo Clavijo
 
The case for consumer-driven contracts
DiUS
 
Consumer-driven contracts with Pact and PHP
Andy Kelk
 
Consumer Driven Contracts - A Deep Dive
Ramya Authappan
 
ATAGTR2017 CDC Tests - Integration Tests cant be made simpler than this!
Agile Testing Alliance
 
vodQA(Pune) 2018 - Consumer driven contract testing using pact
vodQA
 
Measuring Integration Service Quality Gap in A Service System Network
Stephen Kwan
 
Mastering the api hell
Florian Pfleiderer
 
Consumer Driven Contracts (DDD Perth 2016)
Rob Crowley
 
How to analyze a Performance issue
Fabien Raynaud
 
Consumer Driven Contract.pdf
Danylenko Max
 
Move fast and consumer driven contract test things
Alon Pe'er
 
MongoDB World 2019: How Braze uses the MongoDB Aggregation Pipeline for Lean,...
MongoDB
 
CDC Tests - Integration Tests cant be made simpler than this!
Ramya Authappan
 
INFORMS 2014 - The Integration Quality Gap in Service System Networks
Stephen Kwan
 
The 23 Social and Digital Services Your Agency Should Be Selling, But Probabl...
agencyside
 
23 social and digital services agencies should offer
BOLO Conference
 
Agile Contracts
Johannes Brodwall
 
HandyMan(SRS Final Presentation)
FazleRabbi80
 
Architectural Considerations For Complex Mobile And Web Applications
IndicThreads
 

Recently uploaded (20)

PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Ad

Collaborating with Contracts