Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)
-
Upload
pierre-vincent -
Category
Software
-
view
386 -
download
1
Transcript of Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)
![Page 1: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/1.jpg)
Consumer-driven contractsAvoid microservices integration hell!
@PierreVincent
Nov 8th, 2016
![Page 2: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/2.jpg)
Pierre VincentTechnical Team Lead at Newsweaver
techblog.newsweaver.com
@PierreVincent
![Page 3: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/3.jpg)
From this... … to this.
![Page 4: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/4.jpg)
LoginService
UserService
APIGET /users/pierre
{ "user": "pierre", "name": "Pierre Vincent", "role": "publisher"}
200 OK
How do we test this?
![Page 5: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/5.jpg)
Running in Prod Tests Pass in Build
Implement changes
Deployed in Prod
User Service
LoginService
!
✓ ✓ ✓ ✓
✓
{ ... "role": "editor"}
{ ... "roles": ["publisher","editor"]}
Running in Prod
✓ ✓
![Page 6: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/6.jpg)
Maybe we should have tested before deploying to production…?
Tested what though?
![Page 7: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/7.jpg)
UsersService
LoginService
IP CheckService
Token Gen
Service
Cert/KeyService
LoginFrontend
We only wanted to
test this bit!
![Page 8: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/8.jpg)
Contract
LoginService
UserService
API
Authentication Team Users Team
![Page 9: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/9.jpg)
[docs.pact.io]
PACT Specification
Verification philosophy: Tolerant Reader
Implementation guidelines
Implementations
![Page 10: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/10.jpg)
LoginService
UserService
API
PactMock
Server
Authentication Team Users Team
PactConsumerUnit Test
Define interaction
Trigger interaction
GeneratePact
PactProvider
Test
SharePact
Replay interaction
Replay & Verify
Play &Record
![Page 11: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/11.jpg)
Consumer
Provider
Provider State
Request
ExpectedResponse
Login Service
User Service
Given that user 'pierre' exists
Method GETPath /users/pierreHeaders
Accept: application/json
Status 200Headers
Content-Type: application/jsonBody
{ "user": "pierre", "name": "Pierre Vincent", "role": "publisher"}
Interaction
![Page 12: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/12.jpg)
UserService
API
1. Set Provider State
2. Send Request
3. Verify Response
Interaction Verification Test
INSERT INTO users [...]
GET /users/pierreAccept: application/json
{ "user": "pierre", ...}
{ "user": "pierre", ...}
?
![Page 13: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/13.jpg)
AuthenticationDev Team
UsersDev Team
CMSDev Team
BillingDev Team
Pact Broker
PACTPACT PACTPACT
PACTPACT
PACTPACT
PACT
PACT
![Page 14: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/14.jpg)
Pact Broker
DependencyGraphs
Living documentation by example
✓ Versioning
✓ Tagging
✓ REST ApiBuild/Deployment Pipeline integration
![Page 15: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/15.jpg)
Provider pipeline
Implement changes Get Pacts from Broker Replay & Verify Interactions
Deploy Service
Build
Deploy to EU
PROD-EU
Get Pacts from Broker Replay & Verify Interactions
Stop deployment of incompatible Provider
Stop introduction of breaking change
PROD-US
PROD-EU
![Page 16: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/16.jpg)
Consumer pipeline
Implement changes
Generate Pacts (Build)
Push Pacts to Broker Tag Pacts
Each Provider verifies Pacts Deploy Service Tag Pacts
Build
Deploy to EU
HEAD
Stop deployment of incompatible
Consumer
HEAD
PROD-EU
![Page 17: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/17.jpg)
Caution: side-effects may include teams collaborating on API design
![Page 18: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/18.jpg)
Provider state setup for each interaction
Confidence comes from coverage:don’t limit to happy paths
Automation withindeployment pipeline isn’t trivial
What’s the catch…?
![Page 19: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/19.jpg)
After 2 years of CDCs...
Increased confidence when coding & deploying
✓Collaborative API design
✓Living API documentation
✓
![Page 20: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/20.jpg)
Pact docs.pact.io, github.com/pact-foundationPact Broker github.com/bethesque/pact_broker
Try it out!
“Pact Matrix” (Beth Skurrie) rea.tech/enter-the-pact-matrix-or-how-to-decouple-the-release-cycles-of-your-microservices
Why should you use CDC for microservices integration teststechblog.newsweaver.com/why-should-you-use-consumer-driven-contracts-for-microservices-integration-tests
Sharing CDCs with Pact Brokertechblog.newsweaver.com/sharing-consumer-driven-contracts-with-pact-broker
More reading...
![Page 21: Consumer-driven contracts: avoid microservices integration hell! (MuCon London - Nov 2016)](https://reader035.fdocuments.in/reader035/viewer/2022070602/587bbb561a28abb8258b64e9/html5/thumbnails/21.jpg)
techblog.newsweaver.com
Questions?
@PierreVincent