Slide 1

Slide 1 text

Break your event chains! Complex event flows in distributed systems. @berndruecker @martinschimak

Slide 2

Slide 2 text

Berlin, Germany bernd.ruecker@camunda.com @berndruecker Bernd Ruecker Co-founder and Developer Advocate of Camunda

Slide 3

Slide 3 text

Vienna, Austria martin.schimak@plexiti.com @martinschimak Martin Schimak Into and onto de|coding domain language with Plexiti

Slide 4

Slide 4 text

Distributed systems

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Let‘s have a look what we can learn from DDD

Slide 7

Slide 7 text

Example process / Event Storming! Goods shipped Order placed Goods fetched Payment received Events are a concept easy to grasp for everybody in the room.

Slide 8

Slide 8 text

Events are … Payment received Payment Strong consistency It already happened. Events let us look into the past.

Slide 9

Slide 9 text

Events help to decouple services. Order summary Payment received Payment UI raises projected onto Payment Service Order Service

Slide 10

Slide 10 text

Events help with cross-cutting concerns. Payment received Inform customer listened to by Payment Service Notification Service

Slide 11

Slide 11 text

What about purely event-driven architectures? Order placed Payment Service Payment received Inventory Service Goods fetched Shipment Service Goods shipped When relying only on events, „intent“ is always formed inside the event consumer.

Slide 12

Slide 12 text

Autonomous services can make their own decisions. To change the order of two services, we touch 4 sticky notes… but wait, even three services! Shipment Service Goods shipped Order placed Inventory Service Goods fetched Payment Service Payment received

Slide 13

Slide 13 text

Our policies decide to act on facts – with commands Domain Event Policy Command listened to by triggers

Slide 14

Slide 14 text

Who owns the policy in a pure event choreography? Payment received Start Fetching Policy Fetch goods listened to by triggers Payment Service Inventory Service

Slide 15

Slide 15 text

Neither of both truly „owns“ that policy? Payment received Fetch goods listened to by triggers Payment Service Inventory Service Start Fetching Policy

Slide 16

Slide 16 text

Extracting the policy into a mediator service Payment received Fetch goods listened to by triggers Payment Service Inventory Service Order Service Start Fetching Policy

Slide 17

Slide 17 text

The order as the company‘s core business Place order Order placed Request payment Order Service Payment received Fetch goods Goods fetched Ship goods Goods shipped “When the order is placed…” “When the payment is received…” “When the goods are fetched…” “Then we are done!” Mark order as fulfilled Order fulfilled Payment Service Inventory Service Shipment Service

Slide 18

Slide 18 text

Double check: what happens when we charge later? Place order Order placed Request payment Order Service Payment received Fetch goods Goods fetched Ship goods Goods shipped “When the order is placed…” “When the payment is received…” “When the goods are fetched…” “Then we are done!” Mark order as fulfilled Order fulfilled Payment Service Inventory Service Shipment Service “When the order is placed…” “When the payment is received…” “When the goods are fetched…”

Slide 19

Slide 19 text

Multiple services need to collaborate Payment Shipping Order Inventory

Slide 20

Slide 20 text

Multiple services need to collaborate Payment Shipping Order Inventory https://www.infoworld.com/article/3254777/application-development/ 3-common-pitfalls-of-microservices-integrationand-how-to-avoid-them.html

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

„There was an error while sending your boarding pass“

Slide 23

Slide 23 text

Check-in Web-UI Me Current situation

Slide 24

Slide 24 text

Check-in Barcode Generator Web-UI Me Output Mgmt Current situation

Slide 25

Slide 25 text

Check-in Barcode Generator Web-UI Me Output Mgmt Current situation – the bad part

Slide 26

Slide 26 text

Check-in Barcode Generator Web-UI Me Output Mgmt Current situation – the bad part

Slide 27

Slide 27 text

Check-in Barcode Generator Web-UI Me Output Mgmt Current situation – the bad part Stateful Retry

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

We are having some technical difficulties 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. …I just made this up…

Slide 30

Slide 30 text

Check-in Barcode Generator Web-UI Me Output Mgmt Possible situation – much better!

Slide 31

Slide 31 text

Check-in Barcode Generator Web-UI Me Output Mgmt Possible situation – much better! Stateful Retry

Slide 32

Slide 32 text

Check-in Barcode Generator Web-UI Me Output Mgmt Stateful Retry Possible situation – much better! The failure never leaves this scope!

Slide 33

Slide 33 text

Persist thing (Entity, Document, Actor, …) State machine or workflow engine Typical concerns DIY = effort, accidental complexity Complex, proprietary, heavyweight, slow, don‘t scale, developer adverse Scheduling, Versioning, operating, visibility, scalability, … Handling State

Slide 34

Slide 34 text

Workflow engines, state machines It is relevant in modern architectures

Slide 35

Slide 35 text

CADENCE Silicon valley has recognized Workflow engines, state machines

Slide 36

Slide 36 text

CADENCE There are lightweight open source options Workflow engines, state machines

Slide 37

Slide 37 text

CADENCE also at scale Workflow engines, state machines

Slide 38

Slide 38 text

CADENCE for todays demo Workflow engines, state machines

Slide 39

Slide 39 text

Check-in Barcode Generator Web-UI Me Output Mgmt A state machine!

Slide 40

Slide 40 text

Check-in Barcode Generator Web-UI Me Output Mgmt A state machine!

Slide 41

Slide 41 text

Example Credit Card Payment REST also available in C#

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

Payment Now you have a state machine! Credit Card REST

Slide 44

Slide 44 text

Distributed systems introduce complexity you have to tackle! Credit Card Payment REST

Slide 45

Slide 45 text

Distributed systems

Slide 46

Slide 46 text

It is impossible to differentiate certain failure scenarios. Independant of communication style! Service Provider Client

Slide 47

Slide 47 text

Distributed systems introduce complexity you have to tackle! Credit Card Payment REST

Slide 48

Slide 48 text

Distributed systems introduce complexity you have to tackle! Credit Card Payment REST Do it reliably

Slide 49

Slide 49 text

Distributed systems 2007

Slide 50

Slide 50 text

Distributed transactions using compensation * Compensation *aka Saga pattern

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

Long running services Credit Card Payment Order

Slide 53

Slide 53 text

God services? Credit Card Payment A few smart god services tell anemic CRUD services what to do Sam Newmann Order

Slide 54

Slide 54 text

God services? Credit Card Payment Order A few smart god services tell anemic CRUD services what to do Sam Newmann

Slide 55

Slide 55 text

„By delegating our problems to our clients we force them into mitigation. They become god services.“ Credit card failed Retry with new credit card details Charge credit card listened to by triggers Payment Service Order Service

Slide 56

Slide 56 text

Just the first requirements for a payment service Request payment Payment received Payment requested Charge credit card Depending on account balance Withdraw amount from account Amount Withdrawn Credit card charged Credit card failed Update credit card details Account details Credit card details updated Whenever card details are updated After two weeks Depending on the amount Amount credited Mark payment received Mark payment canceled Payment canceled Credit amount to account Whenever payment is canceled Mark payment received Payment received

Slide 57

Slide 57 text

Payment as a „long-running“ service Request payment Payment received Payment canceled 1) creates value – serving a result its client is really interested in 2) assumes responsibility – instead of delegating troubles with internal steps to its client 3) may go asynchronous – if needed for composite execution Payment Service

Slide 58

Slide 58 text

@Saga class Payment { private var paymentAmount = 0F @StartSaga @SagaEventHandler(associationProperty = "paymentId") fun on(event: PaymentRequested) { } } e.g. Axon Messaging & Saga Management is cool, but Java works as well! :-) 1) Correlate domain event 2) Save process state 3) Evaluate business policy 4) Create and issue command

Slide 59

Slide 59 text

Credit amount back to account Withdraw amount from cust. account Charge amount by credit card e.g. with Camunda as message-driven workflow Charge amount by credit card Credit amount back to account Update credit card details Check customer account balance Payment requested Depending on account balance Charge credit card Withdraw amount from account Credit card charged Whenever credit card is charged Mark payment received Payment received Amount Withdrawn Depending on the amount Mark payment received Payment received Mark paym. partly covered Payment partly covered Whenever payment p. covered Charge credit card Credit card failed Whenever credit card failed Update credit card details Credit card details updated Whenever card details are updated Charge credit card After two weeks Mark payment canceled Payment canceled Whenever payment is canceled Credit amount to account Amount credited Every two days Remind customer Customer reminded Withdraw amount from cust. account

Slide 60

Slide 60 text

DDD? Long-running services respect bounded contexts! Order service Payment service Request payment Payment received Request payment Payment canceled

Slide 61

Slide 61 text

Integration of Axon Messaging with Camunda. Order service Payment service Request payment Payment received Payment canceled Request payment plexiti de|coding domain language @martinschimak https://github.com/plexiti/axon-camunda-poc

Slide 62

Slide 62 text

Flowing retail example: https://github.com/flowing/flowing-retail/ Using Java + Spring Boot or C# REST or Kafka Camunda or Zeebe

Slide 63

Slide 63 text

Zeebe.io

Slide 64

Slide 64 text

bernd.ruecker@camunda.com @berndruecker http://bernd-ruecker.com/ martin.schimak@plexiti.com @martinschimak http://plexiti.com/ https://github.com/plexiti/axon-camunda-poc/ http://github.com/flowing/flowing-retail/ https://www.infoq.com/articles/events- workflow-automation Contact: Contact: Examples: https://www.infoworld.com/article/3254777/ application-development/ 3-common-pitfalls-of-microservices- integrationand-how-to-avoid-them.html With thoughts from http://flowing.io @berndruecker | @martinschimak