71
Distributed Orchestration of Microservices [email protected] | @berndruecker Co-Founder & Developer Advocate Camunda With thoughts from http://flowing.io @berndruecker | @martinschimak

Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Distributed Orchestration of Microservices

[email protected] | @berndruecker

Co-Founder & Developer Advocate CamundaWith thoughts from http://flowing.io@berndruecker | @martinschimak

Page 2: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Co-founder and Developer Advocate ofCamunda

Berlin, Germany

[email protected]@berndruecker

Bernd Ruecker

Page 3: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks
Page 4: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

3 common hypotheses I check today:

# Events decrease coupling# Orchestration needs to be avoided# Workflow engines are painful

Page 5: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Simplified example:dash button

Photo by 0xF2, available under Creative Commons BY-ND 2.0 license. https://www.flickr.com/photos/0xf2/29873149904/

Page 6: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Three steps…

Page 7: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Who is involved?

Checkout

Payment

Inventory

Shipment

Page 8: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Autonomous (micro-)services

Checkout

Payment

Inventory

Shipment

Dedicated Application Processes

Dedicated infrastructure

Dedicated Development Teams

Page 9: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Events decrease coupling

Page 10: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Request/response: temporal coupling

Checkout

Payment

Inventory

Shipment

RequestResponse

The button blinks if we canship within 24 hours

Page 11: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Temporal decoupling with events and read models

Checkout

Payment

Inventory

Shipment

GoodStored

Read Model

GoodFetched

The button blinks if we canship within 24 hours

*Events are facts about what happened (in the past)

Page 12: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Events can decrease coupling*

*e.g. decentral data-management, read models, extract cross-cutting aspects

Page 13: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Peer-to-peer event choreography

Checkout

Payment

Inventory

Shipment

Order placed

Payment received

Goodsshipped

Goodsfetched

Page 14: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Peer-to-peer event choreography

Checkout

Payment

Inventory

Shipment

Order placed

Payment received

Goodsshipped

Goodsfetched

Fetch the goodsbefore thepayment

Page 15: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Peer-to-peer event choreography

Checkout

Payment

Inventory

Shipment

Fetch the goodsbefore thepayment

Goodsfetched

Order placed

Payment received

Goodsshipped

Page 16: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Peer-to-peer event choreography

Checkout

Payment

Inventory

Shipment

Fetch the goodsbefore thepayment

Customers canpay via invoice

Goodsfetched

Order placed

Payment received

Goodsshipped

Page 17: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Photo by born1945, available under Creative Commons BY 2.0 license.

Page 18: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Order

Extract the end-to-end responsibility

Checkout

Payment

Inventory

Shipment

*Commands have an intent about what needs to happen in the future

Order placed

Paymentreceived

Retrievepayment

Page 19: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Commands help to avoid(complex) peer-to-peer event chains

Page 20: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Orchestration needs to be avoided

Page 21: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Smart ESB-like middleware

Checkout

Payment

Inventory

Shipment

Order

Order placed

Payment received

Goodfetched

Goodshipped

Page 22: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Dumb pipes

Checkout

Payment

Inventory

Shipment

Order

Smart endpoints and dumb pipes

Martin Fowler

Page 23: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Danger of god services?

Checkout

Order

A fewsmart god services tellanemic CRUD services what to do

Sam Newmann

Payment

Inventory

Shipment

Page 24: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Danger of god services?

Checkout

Payment

Inventory

Shipment

Order

A fewsmart god services tellanemic CRUD services what to do

Sam Newmann

Page 25: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

A god service is only createdwith bad API design!

Page 26: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Who is responsible to deal with problems?

Order Payment

RetrievePayment

Page 27: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Who is responsible to deal with problems?

Order PaymentCreditCard

RetrievePayment

Page 28: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Who is responsible to deal with problems?

Order PaymentCreditCard

RetrievePayment

Rejected

Page 29: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Who is responsible to deal with problems?

Order Payment

Client of dumb endpoints easily become a god services.

If the creditcard was

rejected, thecustomer canprovide new

details

CreditCard

RetrievePayment

RejectedRejected

Page 30: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Paymentcanceled

Who is responsible to deal with problems?

Order Payment

If the credit card was

rejected, the customer can provide new

details

CreditCard

RetrievePayment

Rejected

Paymentreceived

Page 31: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Paymentcanceled

Who is responsible to deal with problems?

Order Payment

Clients of smart endpoints remains lean.

If the credit card was

rejected, the customer can provide new

details

CreditCard

RetrievePayment

Rejected

Paymentreceived

Smart endpoints are potentially long-running

Page 32: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Photo by Tookapic, available under Creative Commons CC0 1.0 license.

Page 33: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

„There was an errorwhile sending your

boarding pass“

Page 34: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Check-in

Web-UI

Me

Current situation

Page 35: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation

Page 36: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation

Page 37: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation – the bad part

Page 38: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation – the bad part

StatefulRetry

Page 39: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks
Page 40: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Possible situation – much better!

Page 41: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Possible situation – much better!

StatefulRetry

Page 42: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

StatefulRetry

Possible situation – much better!

The failurenever leavesthis scope!

Page 43: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Persist thing(Entity, Actor, …)

State machine orworkflow engine

Typicalconcerns

DIY = effort, accidentalcomplexity

Scheduling, Versioning, operating, visibility, scalability, …

Handling State

Page 44: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Workflow engines are painful

Complex, proprietary, heavyweight, central, developer adverse, …

Page 45: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Workflow engines, state machines

It is

relevantin modern

architectures

Page 46: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

CADENCE

Silicon valleyhas recognized

Workflow engines, state machines

Page 47: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

CADENCEWorkflow engines, state machines

Page 48: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

CADENCE

also at scaleWorkflow engines, state machines

Page 49: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

CADENCE

for todays demo

Workflow engines, state machines

Page 50: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Payment

The workflow engine handles state

CreditCardREST

Page 51: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Fallbacks increase resilience

CreditCard

PaymentREST

Page 52: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Distributedsystems

Page 53: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

It is impossible todifferentiate certain

failure scenarios.

Independant ofcommunication style!

Service Provider

Client

Page 54: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

One HTTP call introduces complexity you have to tackle!

CreditCard

PaymentREST

Page 55: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

One HTTP call introduces complexity you have to tackle!

CreditCard

PaymentREST

Page 56: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Timeouts

Page 57: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Distributedsystems

Page 58: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Business transaction / compensation*

Page 59: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Living documentation for long-running behaviour

Page 60: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

A visual HTML report for a specific test case

Page 61: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Do you prefer coded or graphical DSLs?

Bpmn.createExecutableProcess("order")//....sendTask("RetrievePayment").camundaClass(RetrievePaymentAdapter.class).receiveTask("PaymentReceived").message("PaymentReceivedEvent")//...

* BPMN - ISO notation for modeling andexecuting long-running processes and flows

Page 62: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Before mapping processes explicitly with BPMN, the truth was buried in the code and nobody knew what was going on.

Jimmy Floyd, 24 Hour Fitnesse

Page 63: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Workflows live inside service boundaries

Page 64: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Manigfold architecture options

https://blog.bernd-ruecker.com/architecture-options-to-run-a-workflow-engine-6c2419902d91

Page 65: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Lightweight workflow engines aregreat – don‘t DIY*

*e.g. enabling potentially long-running services, solving harddeveloper problems, can run decentralized

Page 66: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks
Page 67: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Zalando

Sales-Order and

Order-Fulfillment

via Camunda

for every order worldwide

Orders Q2-2017: 22,2 Mio.

Sales 2016: 3,6 Mrd. EUR

Growth 2016: 23%

Page 68: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Some code

InventoryPaymentOrder ShippingCheckout Monitor

https://github.com/flowing/flowing-retail/

Human Tasks

H2 H2

Page 69: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

# Events decrease coupling: sometimesread-models, but no complex peer-to-peer event chains!

# Orchestration needs to be avoided: sometimesno ESB, smart endpoints/dumb pipes, important capabilities need a home

# Workflow engines are painful: some of themlightweight engines are easy to use and can run decentralized,they solve hard developer problems, don‘t DIY

Page 70: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

Thank you!

Page 71: Distributed Orchestration of Microservices...Temporal decoupling with events and read models Checkout Payment Inventory Shipment Good Stored Read Model Good Fetched The button blinks

[email protected]@berndruecker

https://bernd-ruecker.com

https://blog.bernd-ruecker.com

https://github.com/flowing

https://www.infoq.com/articles/events-workflow-automation With thoughts from http://flowing.io

@berndruecker | @martinschimak

Contact:

Slides:

Blog:

Code:

https://www.infoworld.com/article/3254777/application-development/3-common-pitfalls-of-microservices-integrationand-how-to-avoid-them.html