Slide 1

Slide 1 text

Events, Workflows, Sagas? Complex Workflows in Distributed Applications 1 Mastodon @[email protected] LinkedIn https://linkedin.com/in/lutzh Blog https://www.reactivesystems.eu/

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

@[email protected] Why me? - Built my first message-driven, asynchronous system for the Bundesbank in 2002 - Worked on various Event-Driven systems, e.g. for Zalando, ING, ista, Maersk - Currently building a bank !) with Event-Driven Architecture, Microservices, DDD 3

Slide 4

Slide 4 text

Slide 5

Slide 5 text

Slide 6

Slide 6 text

Slide 7

Slide 7 text

Slide 8

Slide 8 text

Slide 9

Slide 9 text

Slide 10

Slide 10 text

@[email protected] 10 10 Event-Driven Architecture Google Trend

Slide 11

Slide 11 text

@[email protected] Reminder: Queries, Commands, Events 11 Is.. Query A request for information about the current state of one or many objects Command An intention to perform an operation or change a state Event A fact, something that undisputedly happened in the past

Slide 12

Slide 12 text

Slide 13

Slide 13 text

Slide 14

Slide 14 text

Slide 15

Slide 15 text

@[email protected] Reminder: Queries, Commands, Events 15 Is.. Expected Response Query A request for information about the current state of one or many objects The requested information Command An intention to perform an operation or change a state A confirmation that the command has been executed, or an error message if the command failed Event A fact, something that undisputedly happened in the past None (events are facts, they can’t “fail”)

Slide 16

Slide 16 text

@[email protected] Reminder: Queries, Commands, Events 16 Is.. Expected Response Communication Pattern Query A request for information about the current state of one or many objects The requested information Request-Response Command An intention to perform an operation or change a state A confirmation that the command has been executed, or an error message if the command failed Request-Response Event A fact, something that undisputedly happened in the past None (events are facts, they can’t “fail”) Fire-and-Forget

Slide 17

Slide 17 text

@[email protected] Reminder: Queries, Commands, Events 17 Is.. Expected Response Communication Pattern Query A request for information about the current state of one or many objects The requested information Request-Response Command An intention to perform an operation or change a state A confirmation that the command has been executed, or an error message if the command failed Request-Response Event A fact, something that undisputedly happened in the past None (events are facts, they can’t “fail”) Fire-and-Forget But how can I know it’ll be picked up and processed?

Slide 18

Slide 18 text

@[email protected] 18 Synchronous Command Asynchronous Command Asynchronous Event

Slide 19

Slide 19 text

@[email protected] Events are “fire-and-forgetˮ... … but based on previous agreements (promises) 19

Slide 20

Slide 20 text

@[email protected] Reminder: Queries, Commands, Events 20 Is.. Expected Response Communication Pattern Query A request for information about the current state of one or many objects The requested information Request-Response Command An intention to perform an operation or change a state A confirmation that the command has been executed, or an error message if the command failed Request-Response Event A fact, something that undisputedly happened in the past None (events are facts, they can’t “fail”) Fire-and-Forget (rely on promises) But surely there’ll still be errors we need to handle?

Slide 21

Slide 21 text

Slide 22

Slide 22 text

Slide 23

Slide 23 text

@[email protected] Brain Teaser Functional Programming 23

Slide 24

Slide 24 text

Slide 25

Slide 25 text

Slide 26

Slide 26 text

@[email protected] 26 item, err := reserveItem(itemNumber) if err != nil { return nil, errors.New("out of stock") } confirmation, err := getPayment(itemNumber) if err != nil { return nil, errors.New("insufficient funds") } result, err := shipItem(itemNumber)

Slide 27

Slide 27 text

@[email protected] 27 reserveItem(itemNumber).flatMap(getPayment).flatMap(shipItem)

Slide 28

Slide 28 text

@[email protected] The unreasonable effectiveness of events: Beyond asynchronous communication, being event-driven has a massive effect on the overall workflow and system design. Event-Driven Architecture EDA) is at least as much about the flow as it is about the actual events. 28

Slide 29

Slide 29 text

@[email protected] Brain Teaser: We could treat a command like an event 29 Is.. Expected Response Communication Pattern Command An intention to perform an operation or change a state None (receiver is not allowed to reject) Fire-and-Forget Event A fact, something that undisputedly happened in the past None (events are facts, they can’t “fail”) Fire-and-Forget

Slide 30

Slide 30 text

@[email protected] Maybe, instead of Event-Driven Architecture, we should talk about microworkflows? 30 Coming soon: https://microworkflows.org

Slide 31

Slide 31 text

@[email protected] Events help us to avoid two types of coupling: - Temporal Coupling (leading to better scalability and resilience) - Control Coupling (leading to enhanced organizational clarity / domain boundaries) 31

Slide 32

Slide 32 text

Slide 33

Slide 33 text

@[email protected] Workflow Engines, Durable Execution, Sagas 33

Slide 34

Slide 34 text

Slide 35

Slide 35 text

@[email protected] The Saga Pattern 35

Slide 36

Slide 36 text

@[email protected] 36 How it started How itʼs going

Slide 37

Slide 37 text

Slide 38

Slide 38 text

38

Slide 39

Slide 39 text

@[email protected] Orchestration vs. Choreography While these are fitting terms to describe the concepts, most comparisons are not useful, but based on some folkloristic concerns. Hence I often try to avoid them. 39

Slide 40

Slide 40 text

@[email protected] Example Heuristic “Complex workflows..ˮ Problem: Taking a workflow as given, not as something that is designed and can be changed. Remember 2-phase-commit? 40

Slide 41

Slide 41 text

@[email protected] Think reducing complexity, not managing it. https://twitter.com/bitfield/status/1411731604335214592 41

Slide 42

Slide 42 text

@[email protected] Workflows and Orchestration are useful tools. Workflow engines too. But not for implementing complex workflows on top of Microservices. That use case shouldnʼt exist. Consider going event-driven instead. Break the workflow down into microworkflows. 42

Slide 43

Slide 43 text

@[email protected] Orchestration and Choreography can complement each other. Orchestration within a bounded context. Within a microworkflow. As an integration tool. Choreography between different bounded contexts / between microworkflows. 43

Slide 44

Slide 44 text

@[email protected] Event-Driven Architecture ● enables scalability, resilience (removes temporal coupling) ● promotes clear responsibility boundaries (removes control coupling) 44

Slide 45

Slide 45 text

@[email protected] Event-Driven Architecture Thinking in events is not enough - youʼll also need to think in terms of promises and railways. Make sure not to approach it with an imperative mindset. 45

Slide 46

Slide 46 text

What do you think? Letʼs discuss! Please rate your experience ⭐⭐⭐⭐⭐ 46 Mastodon @[email protected] LinkedIn https://linkedin.com/in/lutzh Blog https://www.reactivesystems.eu/

Slide 47

Slide 47 text

@[email protected] Important Patterns 47

Slide 48

Slide 48 text

@[email protected] 48 Separate Observing from Control

Slide 49

Slide 49 text

@[email protected] 49 Bring the data to the process

Slide 50

Slide 50 text

Slide 51

Slide 51 text

@[email protected] More Brain Teasers 51

Slide 52

Slide 52 text

@[email protected] Think Unix Philosophy 1. Make each program do one thing well. To do a new job, build afresh rather than complicate old programs by adding new "features". 2. Expect the output of every program to become the input to another, as yet unknown, program. ... 52 $ Cat file3.txt | grep “dwx” | tee file4.txt | wc –l

Slide 53

Slide 53 text

@[email protected] Think Stream Processing 53

Slide 54

Slide 54 text

@[email protected] Think Actors 54 Supervisor Actor Client