Complex event flows in distributed systems @berndruecker - - PowerPoint PPT Presentation

complex event flows in
SMART_READER_LITE
LIVE PREVIEW

Complex event flows in distributed systems @berndruecker - - PowerPoint PPT Presentation

Complex event flows in distributed systems @berndruecker @berndruecker 3 common hypotheses I check today: # Events decrease coupling # Orchestration needs to be avoided # Workflow engines are painful Warning: Contains Opinion Bernd Ruecker


slide-1
SLIDE 1

Complex event flows in distributed systems

@berndruecker

slide-2
SLIDE 2

3 common hypotheses I check today: # Events decrease coupling # Orchestration needs to be avoided # Workflow engines are painful

@berndruecker

slide-3
SLIDE 3

Warning: Contains Opinion

slide-4
SLIDE 4

Berlin, Germany

mail@berndruecker.io @berndruecker

Bernd Ruecker

Co-founder and Chief T echnologist of Camunda

slide-5
SLIDE 5
slide-6
SLIDE 6

Simplified example: dash button

Photo by 0xF2, available under Creative Commons BY-ND 2.0

  • license. https://www.flickr.com/photos/0xf2/29873149904/

@berndruecker

slide-7
SLIDE 7

Three steps…

@berndruecker

slide-8
SLIDE 8

Who is involved? Some bounded contexts…

Checkout Payment Inventory Shipment

@berndruecker

slide-9
SLIDE 9

(Micro-)services

Checkout Payment Inventory Shipment

@berndruecker

slide-10
SLIDE 10

Autonomous (micro-)services

Checkout Payment Inventory Shipment

Dedicated Application Processes Dedicated infrastructure Dedicated Development Teams @berndruecker

slide-11
SLIDE 11

Events decrease coupling

@berndruecker

slide-12
SLIDE 12

Example

Checkout Payment Inventory Shipment

The button blinks if we can ship within 24 hours

@berndruecker

slide-13
SLIDE 13

Request/response: temporal coupling

Checkout Payment Inventory Shipment

Request Response

The button blinks if we can ship within 24 hours

@berndruecker

slide-14
SLIDE 14

T emporal decoupling with events and read models

Checkout Payment Inventory Shipment

Good Stored Read Model Good Fetched

The button blinks if we can ship within 24 hours *Events are facts about what happened (in the past)

@berndruecker

slide-15
SLIDE 15

Order Placed Payment Received Goods Fetched

Notification Checkout Payment Inventory Shipment

Event-driven architecture

@berndruecker

slide-16
SLIDE 16

Events can decrease coupling*

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

@berndruecker

slide-17
SLIDE 17

Peer-to-peer event chains

Checkout Payment Inventory Shipment

Order placed Payment received Goods shipped Goods fetched

@berndruecker

slide-18
SLIDE 18

Peer-to-peer event chains

Checkout Payment Inventory Shipment

Order placed Payment received Goods shipped Goods fetched

@berndruecker

slide-19
SLIDE 19

The danger is that it's very easy to make nicely decoupled systems with event notification, without realizing that you're losing sight of that larger-scale flow, and thus set yourself up for trouble in future years.

https://martinfowler.com/articles/201701-event-driven.html @berndruecker

slide-20
SLIDE 20

The danger is that it's very easy to make nicely decoupled systems with event notification, without realizing that you're losing sight of that larger-scale flow, and thus set yourself up for trouble in future years.

https://martinfowler.com/articles/201701-event-driven.html @berndruecker

slide-21
SLIDE 21

The danger is that it's very easy to make nicely decoupled systems with event notification, without realizing that you're losing sight of that larger-scale flow, and thus set yourself up for trouble in future years.

https://martinfowler.com/articles/201701-event-driven.html @berndruecker

slide-22
SLIDE 22

Monitoring Workflows Across Microservices

https://www.infoq.com/articles/monitor-workflow-collaborating-microservices @berndruecker

slide-23
SLIDE 23

T ypical approaches

Distributed T racing Data Lake / Event Monitoring Process Mining Process T racking @berndruecker

slide-24
SLIDE 24

Stefan Tilkov: Microservice Patterns & Antipatterns - MicroXchg 2018

@berndruecker

slide-25
SLIDE 25

Peer-to-peer event chains

Checkout Payment Inventory Shipment

Order placed Payment received Goods shipped Goods fetched

Fetch the goods before the payment

@berndruecker

slide-26
SLIDE 26

Peer-to-peer event chains

Checkout Payment Inventory Shipment

Fetch the goods before the payment

Goods fetched Order placed Payment received Goods shipped

@berndruecker

slide-27
SLIDE 27

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

slide-28
SLIDE 28

What we wanted

Photo by Lijian Zhang, available under Creative Commons SA 2.0 License and Pedobear19 / CC BY-SA 4.0 @berndruecker

slide-29
SLIDE 29

„Challenges?“

Source: Microservices orchestration survey, July 2018, 354 responses https://camunda.com/microservices-orchestration-survey-results-2018/ @berndruecker

slide-30
SLIDE 30

Order

Extract the end-to-end responsibility

Checkout Payment Inventory Shipment

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

Payment received Order placed Retrieve payment

@berndruecker

slide-31
SLIDE 31

Order

It is about where to decide about the coupling!

Checkout Payment Inventory Shipment

Order placed Retrieve payment

Order decides . to listen to the event . to issue the command

@berndruecker

slide-32
SLIDE 32

Order

It is about where to decide about the coupling!

Checkout Payment Inventory Shipment

Order placed Retrieve payment

It can still be messaging!

@berndruecker

slide-33
SLIDE 33

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

@berndruecker

slide-34
SLIDE 34

Orchestration needs to be avoided

@berndruecker

slide-35
SLIDE 35

Smart ESB-like middleware

Checkout Payment Inventory Shipment Order

Order placed Payment received Good fetched Good shipped

@berndruecker

slide-36
SLIDE 36

Dumb pipes

Checkout Payment Inventory Shipment Order

Smart endpoints and dumb pipes

Martin Fowler @berndruecker

slide-37
SLIDE 37

Danger of god services?

Checkout Order

A few smart god services tell anemic CRUD services what to do

Sam Newmann

Payment Inventory Shipment

@berndruecker

slide-38
SLIDE 38

Danger of god services?

Checkout

Payment Inventory Shipment

Order

A few smart god services tell anemic CRUD services what to do

Sam Newmann @berndruecker

slide-39
SLIDE 39

A god service is only created by bad API design!

@berndruecker

slide-40
SLIDE 40

Example

Order Payment

Retrieve Payment

@berndruecker

slide-41
SLIDE 41

Example

Order Payment Credit Card

Retrieve Payment

@berndruecker

slide-42
SLIDE 42

Example

Order Payment Credit Card

Retrieve Payment Rejected

@berndruecker

slide-43
SLIDE 43

Example

Order Payment

If the credit card was rejected, the customer can provide new details

Credit Card

Retrieve Payment Rejected Rejected

@berndruecker

slide-44
SLIDE 44

Example

Order Payment

Client of dumb endpoints easily become a god services. If the credit card was rejected, the customer can

provide new details

Credit Card

Retrieve Payment Rejected Rejected

@berndruecker

slide-45
SLIDE 45

Payment failed

Who is responsible to deal with problems?

Order Payment

If the credit card was rejected, the customer can provide new details

Credit Card

Retrieve Payment Rejected Payment received

@berndruecker

slide-46
SLIDE 46

Payment failed

Long running services

Order Payment Credit Card

Retrieve Payment Rejected Payment received

Smart endpoints are potentially long-running @berndruecker

slide-47
SLIDE 47

Persist thing (Entity, Actor, …) State machine or workflow engine T ypical concerns DIY = effort, accidental complexity

Scheduling, Versioning,

  • perating, visibility,

scalability, …

Handling State

@berndruecker

slide-48
SLIDE 48

Workflow engines are painful

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

@berndruecker

slide-49
SLIDE 49

Avoid the wrong tools!

Death by properties panel

Low-code is great! (You can get rid

  • f your developers!)

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

@berndruecker

slide-50
SLIDE 50

Workflow engines, state machines

It is

relevant

in modern architectures

@berndruecker

slide-51
SLIDE 51

CADENCE

Silicon valley has recognized

Workflow engines, state machines

@berndruecker

slide-52
SLIDE 52

CADENCE

Workflow engines, state machines

@berndruecker

slide-53
SLIDE 53

public static void main(String[] args) { ProcessEngine engine = new StandaloneInMemProcessEngineConfiguration() .buildProcessEngine(); engine.getRepositoryService().createDeployment() // .addModelInstance("flow.bpmn", Bpmn.createExecutableProcess("flow") // .startEvent() .serviceTask("Step1").camundaClass(SysoutDelegate.class) .serviceTask("Step2").camundaClass(SysoutDelegate.class) .endEvent() .done() ).deploy(); engine.getRuntimeService().startProcessInstanceByKey( "flow", Variables.putValue("city", "New York")); } public class SysoutDelegate implements JavaDelegate { public void execute(DelegateExecution execution) throws Exception { System.out.println("Hello " + execution.getVariable("city")); } }

What do I mean by „leightweight?“

@berndruecker

slide-54
SLIDE 54

public static void main(String[] args) { ProcessEngine engine = new StandaloneInMemProcessEngineConfiguration() .buildProcessEngine(); engine.getRepositoryService().createDeployment() // .addModelInstance("flow.bpmn", Bpmn.createExecutableProcess("flow") // .startEvent() .serviceTask("Step1").camundaClass(SysoutDelegate.class) .serviceTask("Step2").camundaClass(SysoutDelegate.class) .endEvent() .done() ).deploy(); engine.getRuntimeService().startProcessInstanceByKey( "flow", Variables.putValue("city", "New York")); } public class SysoutDelegate implements JavaDelegate { public void execute(DelegateExecution execution) throws Exception { System.out.println("Hello " + execution.getVariable("city")); } }

Build engine in one line of code (using in- memory H2)

@berndruecker

slide-55
SLIDE 55

public static void main(String[] args) { ProcessEngine engine = new StandaloneInMemProcessEngineConfiguration() .buildProcessEngine(); engine.getRepositoryService().createDeployment() // .addModelInstance("flow.bpmn", Bpmn.createExecutableProcess("flow") .startEvent() .serviceTask("Step1").camundaClass(SysoutDelegate.class) .serviceTask("Step2").camundaClass(SysoutDelegate.class) .endEvent() .done() ).deploy(); engine.getRuntimeService().startProcessInstanceByKey( "flow", Variables.putValue("city", "New York")); } public class SysoutDelegate implements JavaDelegate { public void execute(DelegateExecution execution) throws Exception { System.out.println("Hello " + execution.getVariable("city")); } }

Define flow e.g. in Java DSL

@berndruecker

slide-56
SLIDE 56

public static void main(String[] args) { ProcessEngine engine = new StandaloneInMemProcessEngineConfiguration() .buildProcessEngine(); engine.getRepositoryService().createDeployment() // .addModelInstance("flow.bpmn", Bpmn.createExecutableProcess("flow") .startEvent() .serviceTask("Step1").camundaClass(SysoutDelegate.class) .serviceTask("Step2").camundaClass(SysoutDelegate.class) .endEvent() .done() ).deploy(); engine.getRuntimeService().startProcessInstanceByKey( "flow", Variables.putValue("city", "New York")); } public class SysoutDelegate implements JavaDelegate { public void execute(DelegateExecution execution) throws Exception { System.out.println("Hello " + execution.getVariable("city")); } }

Define flow e.g. in Java DSL

@berndruecker

slide-57
SLIDE 57

BPMN

Business Process Model and Notation ISO Standard

@berndruecker

slide-58
SLIDE 58

public static void main(String[] args) { ProcessEngine engine = new StandaloneInMemProcessEngineConfiguration() .buildProcessEngine(); engine.getRepositoryService().createDeployment() // .addModelInstance("flow.bpmn", Bpmn.createExecutableProcess("flow") .startEvent() .serviceTask("Step1").camundaClass(SysoutDelegate.class) .serviceTask("Step2").camundaClass(SysoutDelegate.class) .endEvent() .done() ).deploy(); engine.getRuntimeService().startProcessInstanceByKey( "flow", Variables.putValue("city", "New York")); } public class SysoutDelegate implements JavaDelegate { public void execute(DelegateExecution execution) throws Exception { System.out.println("Hello " + execution.getVariable("city")); } }

We can attach code…

@berndruecker

slide-59
SLIDE 59

public static void main(String[] args) { ProcessEngine engine = new StandaloneInMemProcessEngineConfiguration() .buildProcessEngine(); engine.getRepositoryService().createDeployment() // .addModelInstance("flow.bpmn", Bpmn.createExecutableProcess("flow") .startEvent() .serviceTask("Step1").camundaClass(SysoutDelegate.class) .serviceTask("Step2").camundaClass(SysoutDelegate.class) .endEvent() .done() ).deploy(); engine.getRuntimeService().startProcessInstanceByKey( "flow", Variables.putValue("city", "New York")); } public class SysoutDelegate implements JavaDelegate { public void execute(DelegateExecution execution) throws Exception { System.out.println("Hello " + execution.getVariable("city")); } }

…that is called when workflow instances pass through

@berndruecker

slide-60
SLIDE 60

public static void main(String[] args) { ProcessEngine engine = new StandaloneInMemProcessEngineConfiguration() .buildProcessEngine(); engine.getRepositoryService().createDeployment() // .addModelInstance("flow.bpmn", Bpmn.createExecutableProcess("flow") .startEvent() .serviceTask("Step1").camundaClass(SysoutDelegate.class) .serviceTask("Step2").camundaClass(SysoutDelegate.class) .endEvent() .done() ).deploy(); engine.getRuntimeService().startProcessInstanceByKey( "flow", Variables.putValue("city", "New York")); } public class SysoutDelegate implements JavaDelegate { public void execute(DelegateExecution execution) throws Exception { System.out.println("Hello " + execution.getVariable("city")); } }

Start instances

@berndruecker

slide-61
SLIDE 61

Payment

Now you have a state machine!

@berndruecker

slide-62
SLIDE 62

Payment

Easy to handle time

@berndruecker

slide-63
SLIDE 63

Distributed systems

@berndruecker

slide-64
SLIDE 64

Example with synchronous communication

REST

Order Payment Credit Card

@berndruecker

slide-65
SLIDE 65

Example with synchronous communication

REST

Order Payment Credit Card

@berndruecker

slide-66
SLIDE 66

Example with synchronous communication

REST

Order Payment Credit Card

@berndruecker

slide-67
SLIDE 67

Example with synchronous communication

REST

Order Payment Credit Card

Stateful Retry @berndruecker

slide-68
SLIDE 68

Works also for asynchronous communication

Order Payment Credit Card

Monitor Timeouts @berndruecker

slide-69
SLIDE 69

Distributed systems

@berndruecker

slide-70
SLIDE 70

It is impossible to differentiate certain failure scenarios:

Independant of communication style!

Service Provider Client

@berndruecker

slide-71
SLIDE 71

Distributed systems introduce complexity you have to tackle!

Credit Card Payment

REST @berndruecker

slide-72
SLIDE 72

Distributed systems introduce complexity you have to tackle!

Credit Card Payment

REST

The service can be long running. You get a better API and less gods

@berndruecker

slide-73
SLIDE 73

Workflows live inside service boundaries

@berndruecker

slide-74
SLIDE 74

No BPM(N) monoliths

https://blog.bernd-ruecker.com/avoiding-the-bpm-monolith-when-using-bounded-contexts-d86be6308d8 @berndruecker

slide-75
SLIDE 75

Pat Helland

Distributed Systems Guru Worked at Amazon, Microsoft & Salesforce @berndruecker

slide-76
SLIDE 76

Pat Helland

Grown-Ups Don’t Use Distributed T ransactions

Distributed Systems Guru Worked at Amazon, Microsoft & Salesforce @berndruecker

slide-77
SLIDE 77

Distributed transactions using compensation *

Compensation

@berndruecker

slide-78
SLIDE 78

Homework: T ry to do this purely event-driven!

Send to: mail@berndruecker.io @berndruecker

slide-79
SLIDE 79

Biz Dev

Leverage state machine & workflow engine Living documentation Visibility in testing

improve communication improve communication

Ops

@berndruecker

slide-80
SLIDE 80

Visual HTML reports for test cases

@berndruecker

slide-81
SLIDE 81

Living documentation for long-running behaviour

@berndruecker

slide-82
SLIDE 82

Proper Operations

Visibility + Context

@berndruecker

slide-83
SLIDE 83

Biz Dev

Leverage state machine & workflow engine Living documentation Visibility in testing Operate with visibility and context Understand and discuss business processes Evaluate optimizations in-sync with implementation

improve communication improve communication

Ops

@berndruecker

slide-84
SLIDE 84

Monitoring Workflows Across Microservices

https://www.infoq.com/articles/monitor-workflow-collaborating-microservices @berndruecker

slide-85
SLIDE 85

T racking

Checkout Inventory Payment Shipment

Event Bus Workflow Engine https://www.confluent.io/kafka-summit-sf18/the_big_picture @berndruecker

slide-86
SLIDE 86

Journey towards more orchestration

@berndruecker

slide-87
SLIDE 87

Vodafone, Liongate & WDW Presented at CamundaCOn Berlin 2018

slide-88
SLIDE 88

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

@berndruecker

slide-89
SLIDE 89

… It addresses one of the core issues in a distributed microservices architecture—where is the source of truth for the coordinated interaction of the entire system? … the system we are replacing uses a complex peer- to-peer choreography that requires reasoning across multiple codebases to understand.

https://medium.com/@sitapati/node-js-client-for-zeebe-microservices-orchestration-engine-72287e4c7d94

Josh Wulf Credit Sense

@berndruecker

slide-90
SLIDE 90

Lightweight workflow engines are great – don‘t DIY*

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

@berndruecker

slide-91
SLIDE 91

Sales-Order & Order-Fulfillment via Camunda for every order worldwide (Q2 2017: 22,2 Mio)

@berndruecker

slide-92
SLIDE 92

Code, code, code…

@berndruecker

slide-93
SLIDE 93

Event-driven example

Inventory Payment Order Shipping Checkout Monitor

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

Human T asks

H2 H2

@berndruecker

slide-94
SLIDE 94

# Events decrease coupling: sometimes

read-models, but no complex peer-to-peer event chains!

# Orchestration needs to be avoided: sometimes

no ESB, smart endpoints/dumb pipes, balance orchestration and choreography

# Workflow engines are painful: some of them

lightweight engines are easy to use and can run decentralized, they solve hard developer problems, don‘t DIY

@berndruecker

slide-95
SLIDE 95

Thank you!

@berndruecker

slide-96
SLIDE 96

mail@berndruecker.io @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/