Consumer-driven contracts: avoid microservices integration hell! (LondonCD - Oct 2016)

20
Consumer-driven contracts Avoid microservices integration hell! @PierreVincent Oct 11th, 2016

Transcript of Consumer-driven contracts: avoid microservices integration hell! (LondonCD - Oct 2016)

Consumer-driven contractsAvoid microservices integration hell!

@PierreVincent

Oct 11th, 2016

Pierre VincentTechnical Team Lead at Newsweaver

techblog.newsweaver.com

@PierreVincent

From this... … to this.

Login

Service

User

ServiceAPI

GET /users/pierre

{

"user": "pierre",

"name": "Pierre Vincent",

"role": "publisher"

}

200 OK

How do we test this?

Running in ProdTests Pass in

Build

Implement

changes

Deployed in

Prod

User

Service

Login

Service

!

✓ ✓ ✓ ✓

{

...

"role": "editor"

}

{

...

"roles": ["publisher","editor"]

}

Running in Prod

✓ ✓

Maybe we should have tested before deploying to

production…?

Tested what though?

Users

Service

Login

Service

IP

Check

Service

Token

Gen

Service

Cert/Key

Service

Login

Frontend

We only wanted to

test this bit!

Contract

Login

Service

User

ServiceAPI

Authentication Team Users Team

[docs.pact.io]

PACT Specification

Verification philosophy: Tolerant Reader

Implementation guidelines

Implementations

Login

Service

User

Service

A

P

I

Pact

Mock

Server

Authentication Team Users Team

Pact

Consumer

Unit Test

Define

interaction

Trigger

interaction

Generate

Pact

Pact

Provider

Test

Share

Pact

Replay

interaction

Replay & Verify

Play &Record

Consumer

Provider

Assumption

Request

Expected

Response

Login Service

User Service

Given that user 'pierre' exists

Method GET

Path /users/pierre

Headers

Accept: application/json

Status 200

Headers

Content-Type: application/json

Body

{

"user": "pierre",

"name": "Pierre Vincent",

"role": "publisher"

}

Interaction

Authentication

Dev Team

Users

Dev Team

CMS

Dev Team

Billing

Dev Team

Pact

Broker

PACTPACT

PACTPACT

PACTPACT

PACTPACT

PACT

PACT

Pact

Broker

DependencyGraphs

Living documentation by example

✓ Versioning

✓ Tagging

✓ REST Api

Build/Deployment Pipeline integration

Provider pipeline

Implement changes Get Pacts from BrokerReplay & Verify

Interactions

Deploy Service

Build

Deploy to EU

PROD-EU

Get Pacts from BrokerReplay & Verify

Interactions

Stop deployment of incompatible Provider

Stop introduction of breaking change

PROD-US

PROD-EU

Consumer pipeline

Implement

changes

Generate Pacts

(Build)

Push Pacts to

BrokerTag Pacts

Each Provider verifies Pacts Deploy Service Tag Pacts

Build

Deploy to EU

HEAD

Stop deployment of incompatible Consumer

HEAD

PROD-EU

Caution: side-effects may include teams

collaborating on API design

Provider state setup for each interaction

Confidence comes from coverage:

don’t limit to happy paths

Automation within

deployment pipeline isn’t trivial

What’s the catch…?

After 2 years of CDCs...

Increased confidence when coding & deploying

✓Collaborative API design

✓Living API documentation

Pact docs.pact.io, github.com/pact-foundation

Pact 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 tests

techblog.newsweaver.com/why-should-you-use-consumer-driven-contracts-for-microservices-

integration-tests

Sharing CDCs with Pact Broker

techblog.newsweaver.com/sharing-consumer-driven-contracts-with-pact-broker

More reading...

techblog.newsweaver.com

Questions?

@PierreVincent