Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current...

53
Lost in transaction [email protected] | @berndruecker http://bernd-ruecker.com/ Co-Founder & Developer Advocate

Transcript of Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current...

Page 1: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Lost in transaction

[email protected] | @berndruecker

http://bernd-ruecker.com/

Co-Founder & Developer Advocate

Page 2: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

REST, SOAP,Cloud, Saas,

Microservices, SCS, FaaS, Serverless,

Page 3: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Distributed systems

Page 4: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Distributed systems

Challenges of asynchronicity

DistributedTransactions

Communication is complex

Page 5: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Communication is complex

Challenge #1:

Page 6: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

SomeService

SomeService

SomeService

SomeService

SomeService

SomeService

SomeService

But keep it local! Be resilient.

Failure will happen. Accept it!

Page 7: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Let‘s start with a simple example

CreditCard

Payment

REST

Page 8: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Circuit Breaker

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

Page 9: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Live hacking

Getting from https://github.com/flowing/flowing-retail/blob/master/payment-rest/src/main/java/io/flowing/retail/payment/port/resthacks/PaymentRestHacksControllerV1.java to V2

Page 10: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Fail fastis important

Page 11: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Fail fastis important

but not enough!

Page 12: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

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

Page 13: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

„There was an errorwhile sending your

boarding pass“

Page 14: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Check-in

3D-Barcode

Generator

Web-UI

Me

Output Mgmt

Current situation

Circuit breaker

Page 15: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Check-in

3D-Barcode

Generator

Web-UI

Me

Output Mgmt

Current situation - the bad part

StatefulRetry

Page 16: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

„There was an errorwhile sending your

boarding pass“

Page 17: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

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 18: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Check-in

3D-Barcode

Generator

Web-UI

Me

Output Mgmt

StatefulRetry

Possible situation – much better!

The failurenever leavesthis scope!

Page 19: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Persist thing(Entity, Actor, …)

State machine orworkflow engine

Typicalconcerns

DIY = effort, accidentalcomplexity

Complex, proprietary,

heavyweight, slow, developer adverse

Scheduling, Versioning, operating, visibility, scalability, …

Handling State

Page 20: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

State machines orworkflow engines

CADENCE

Page 21: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Live hacking

Getting to https://github.com/flowing/flowing-retail/blob/master/payment-rest/src/main/java/io/flowing/retail/payment/port/resthacks/PaymentRestHacksControllerV3.java

Page 22: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Check-in

3D-Barcode

Generator

Web-UI

Me

Output Mgmt

Workflows live inside service boundaries

Page 23: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Manigfold architecture options

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

Page 24: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Manigfold architecture options

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

Page 25: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Manigfold architecture options

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

Page 26: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Manigfold architecture options

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

Page 27: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

generateBoardingPass

HTTP 200 OK

HTTP 202 ACCEPTED

Check-in

A synchronous response is possible in thehappy case, otherwise it is switched to

asynchronous processing.

Page 28: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Check-in

3D-Barcode

Generator

Web-UI

Me

Output Mgmt

„Eh – no!“

“The customers want synchronous responses!”

Page 29: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Synchronous communicationis the crystal meth of

distributed programming

Todd Montgomery and Martin Thompson in “How did we end up here” at GOTO Chicago 2015

Page 30: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Challenge #2:

Challenges of asynchronicity

Page 31: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Check-in

3D-Barcode

Generator

Web-UI

Me

Output Mgmt

Asynchronous communication

You need tomonitor timeouts

Page 32: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Check-in

3D-Barcode

Generator

Web-UI

Me

Output Mgmt

Remember…

The failurenever leavesthis scope!

Page 33: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Workflow…

Page 34: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Workflow…

Page 35: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

DuplicatesDuplicates

857621972_ded037d1db_b.jpg

Photo by oz dean, available under Creative Commons BY 2.0 license.

Page 36: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

It is impossible todifferentiate certain

failure scenarios.

This is also true forsynchronous

request/response!

Service Provider

Client

Page 37: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

has to implement

Timeout, Retryhas to implement

Idempotency

Client Service Provider

Page 38: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

We are processing your payment.

Do not leave this page.

And for god sake – do not reload!

It is a businessproblemanyway!

We are currently processing your request. Don‘t worry, it will happen safely –

even if you loose connection. Feel free to reload this page any time!

Page 39: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Who has no problemsoperating a message bus?

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

Page 40: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Manigfold architecture options

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

Page 41: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Manigfold architecture options

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

Page 42: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Challenge #3:

DistributedTransactionsDistributed

Transactions

Page 43: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Distributedsystems

Page 44: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Business transactions (aka Saga pattern)

Compensation

Page 45: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Eventual consistency

Temporarilyinconsistent state

But onlytemporarily!

Page 46: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Live hacking

Getting to https://github.com/flowing/flowing-retail/blob/master/payment-rest/src/main/java/io/flowing/retail/payment/port/resthacks/PaymentRestHacksControllerV6.java

Page 47: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

has to implement

Timeout, Retry, Compensation

has to offer

Compensationhas to implement

Idempotency

Client Service Provider

Page 48: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

has to implement

Timeout, Retry, Compensation

has to offer

Compensationhas to implement

Idempotency

Client Service Provider

Page 49: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Event-driven example also available

InventoryPaymentOrder ShippingCheckout Monitor

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

Human Tasks

H2 H2

Page 50: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Workflows live inside service boundaries*

*in DDD: Bounded Contexts

Page 51: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

# Understand complexity of distributed systems# Know strategies and tools to handle ite.g. Circuit breaker (Hystrix)

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

Page 52: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Thank you!

Page 53: Lost in transactionCircuit breaker. Check-in 3D-Barcode Generator Web-UI Me Output Mgmt Current situation - the bad part Stateful ... (aka Saga pattern) Compensation. Eventual consistency

Contact:[email protected]

@berndruecker

Slides:https://bernd-ruecker.com

Blog:https://blog.bernd-ruecker.com

Code online:https://github.com/flowing

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

@berndruecker | @martinschimak