3 common pitfalls in microservice integration and how to avoid … · circuit breaker photo by...

74
3 Common Pitfalls in Microservice Integration and How to Avoid Them @berndruecker

Upload: others

Post on 25-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

3 Common Pitfalls inMicroservice Integration andHow to Avoid Them

@berndruecker

Page 2: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Distributed systems

Page 3: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license
Page 5: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

SomeService

SomeService

SomeService

SomeService

SomeService

SomeService

SomeService

Failure will happen. Accept it!

But keep it local! Be resilient.

Page 6: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Let‘s start with a simple example

CreditCard

Payment

REST

Page 7: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Live hacking

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

Page 8: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Circuit Breaker

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

Page 9: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Fail fastis important

Page 10: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Fail fastis important

but not enough!

Page 11: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

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

Page 12: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

„There was an errorwhile sending your

boarding pass“

Page 13: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Check-in

Web-UI

Me

Current situation

Page 14: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation

Page 15: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation

Page 16: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation

Circuit breaker

Page 17: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation – the bad part

Page 18: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation – the bad part

Page 19: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation – the bad part

StatefulRetry

Page 20: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license
Page 21: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

We are having some technicaldifficulties and cannot present you

your boarding pass right away.

But we do actively retry ourselves, so lean back, relax and we will send it

on time.

Page 22: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Possible situation – much better!

Page 23: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Possible situation – much better!

StatefulRetry

Page 24: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Persist thing(Entity, Document, Actor, …)

State machine orworkflow engine

Typicalconcerns

DIY = effort, accidentalcomplexity

Complex, proprietary, heavyweight, slow,

don‘t scale,developer adverse

Scheduling, Versioning, operating, visibility, scalability, …

Handling State

Page 25: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Warning:Contains Opinion

Page 26: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Berlin, Germany

http://berndruecker.io/[email protected]@berndruecker

Bernd RueckerCo-founder and Chief Technologist ofCamunda

Page 27: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Workflow engines, state machines

It is

relevantin modern

architectures

Page 28: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

CADENCE

Silicon valleyhas recognized

Workflow engines, state machines

Page 29: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

CADENCEWorkflow engines, state machines

Page 30: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

CADENCE

also at scaleWorkflow engines, state machines

Page 31: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

CADENCE

for todays demo

Workflow engines, state machines

Page 32: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Live hacking

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

Page 33: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Payment

Now you have a state machine!

CreditCardREST

Page 34: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Manigfold architecture options

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

Service A Service B

WF-Engine WF-Engine

Spring Boot Spring Boot

Page 35: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Manigfold architecture options

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

Infrastructure

Service A Service B

WF-Engine WF-Engine

Wildfly WildFly

WARWAR

Page 36: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Manigfold architecture options

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

Service A

WF-Engine

C#Client

Service B

WF-Engine

Node.jsClient

Page 37: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

has to implement

Retryhas to implement

Idempotency

Client Service Provider

Page 38: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license
Page 39: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license
Page 40: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Don‘t worry, it will happen safely –even if you loose connection.

Feel free to reload this page any time!

Page 42: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Requirement: Idempotency of services!

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

Page 43: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Requirement: Idempotency of services!

Photo by Chr.Späth, available under Public Domain.

Page 44: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Make every service idempotent!

CreditCard

Payment

Charge Credit CardcardNumber

amount

Charge Credit CardcardNumber

amounttransactionId

Not idempotent

Idempotent

charge

Page 45: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Distributed systems introduce complexity you have to tackle!

CreditCard

PaymentREST

Page 46: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Distributedsystems

Page 47: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

It is impossible todifferentiate certain

failure scenarios.

Independant ofcommunication style!

Service Provider

Client

Page 48: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Distributed systems introduce complexity you have to tackle!

CreditCard

PaymentREST

Page 49: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Distributed systems introduce complexity you have to tackle!

CreditCard

PaymentREST

Cancel

charge

Page 50: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Executableand mature Easy to

understand*

ISO Standardwidespread

*(for Biz, Dev, and Ops)

BPMNBusiness Process

Model and Notation

Page 51: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

ProperOperations

Visibility + Context

Page 52: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Challenges of asynchronicity

Page 53: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Asynchronous communication

You need tomonitor timeouts

Page 54: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Remember…

The failurenever leavesthis scope!

Page 55: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Workflow…

Page 56: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Workflow…

Page 57: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Who uses a message bus?

Page 58: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Who has no problemsoperating a message bus?

Dead messages | No context | Inaccesible payload | Hard to redeliver | Home-grown message hospitals | …

Page 59: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Manigfold architecture options

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

Page 60: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Manigfold architecture options

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

Page 61: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Manigfold architecture options

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

Page 62: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

DistributedTransactionsDistributed

Transactions

Page 63: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Transactions…

Do A

Do B

+ All ornothing

@berndruecker

Page 64: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Distributedsystems

Page 65: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Pat Helland

Grown-Ups Don’t Use Distributed Transactions

Distributed Systems Guru Worked at Amazon, Microsoft & Salesforce

Page 66: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Distributed transactions using compensation *

Compensation

Page 67: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

„Lost in transaction“

https://vimeo.com/289508460

@berndrueckerhttps://berndruecker.io/lost-in-transaction/

Page 68: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

has to implement

Timeout, Retry, Compensation

has to offer

Compensationhas to implement

Idempotency

Client Service Provider

Page 69: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

has to implement

Timeout, Retry, Compensation

has to offer

Compensationhas to implement

Idempotency

Client Service ProviderDon‘t forgetabout state

Page 70: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Event-driven example also available

InventoryPaymentOrder ShippingCheckout Monitor

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

Human Tasks

H2 H2

Page 71: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

# Be aware of complexity of distributed systems# Know strategies and tools to handle ite.g. Circuit breaker (Hystrix > Resilience4J)

Workflow engine for stateful retry, waiting, timeout and compensation (Camunda)

Page 72: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

Thank you!

Page 73: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license
Page 74: 3 Common Pitfalls in Microservice Integration and How to Avoid … · Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license

[email protected]@berndruecker

https://berndruecker.io

https://medium.com/berndruecker

https://github.com/berndruecker

https://www.infoq.com/articles/events-workflow-automation

Contact:

Slides:

Blog:

Code:

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

https://thenewstack.io/5-workflow-automation-use-cases-you-might-not-have-considered/