Opportunities & Pitfalls of Event-Driven Utopia @berndruecker - - PowerPoint PPT Presentation

opportunities pitfalls
SMART_READER_LITE
LIVE PREVIEW

Opportunities & Pitfalls of Event-Driven Utopia @berndruecker - - PowerPoint PPT Presentation

Opportunities & Pitfalls of Event-Driven Utopia @berndruecker Why this talk Why this talk Agenda Events on the outside 3 Events on the inside 1 Service 1 Service 2 Agenda Events on the outside 3 Events on the inside 1 Service 1


slide-1
SLIDE 1

Opportunities & Pitfalls

  • f

Event-Driven Utopia

@berndruecker

slide-2
SLIDE 2

Why this talk

slide-3
SLIDE 3

Why this talk

slide-4
SLIDE 4

Service 1

Agenda

Service 2

Events on the inside Events on the outside

1 3

slide-5
SLIDE 5

Service 1

Agenda

Service 2

Events on the inside Events on the outside

1 3

Events inside out

2

slide-6
SLIDE 6

Service 1

Agenda

Service 2

Events on the inside

1

Events on the outside

3

Events inside out

2

slide-7
SLIDE 7

Once upon a time…

RDMS Application Client

BBC architecture

(box - arrow – box – arrow - cylinder)

Every architecture diagram you'll ever need

slide-8
SLIDE 8

The great thing about this architecture

RDMS Application

DB gurantees (e.g. ACID)

slide-9
SLIDE 9

The problem

not webscale resiliency is expensive

RDMS Application RDMS

cloud-scale

slide-10
SLIDE 10

Pat Helland

https://vimeo.com/52831373

slide-11
SLIDE 11

Append-only Log

bank account created +2,500 $ transfered

  • 14.99$

paid by credit card

Persistent change

RDMS

Account # Balance 12345 2,500$

Persistent state

Current Balance = 2,485.01 $

slide-12
SLIDE 12

Append-only Log

bank account created +2,500 $ transfered

  • 14.99$

paid by credit card

Persistent change

Event

Bank Account Created 2019/04/16 11:00 # 12345

Event

Money T ransfer Received 2,500$ 2019/04/16 11:00 # 12345

slide-13
SLIDE 13

An example from my world

slide-14
SLIDE 14

mail@berndruecker.io @berndruecker

Bernd Ruecker

Co-founder and Chief T echnologist of Camunda

slide-15
SLIDE 15

We build two different workflow engines. Why?

Camunda BPM Zeebe Persistent State Persistent change

slide-16
SLIDE 16

Workflow Instance Id Current Activity State 2 RetrievePayment running Workflow Instance Id Current Activity State 2 ShipGoods running Workflow Instance Id Current Activity State 2 OrderDelivered ended

2.

  • 3. UPDAT

E

  • 2. UPDAT

E

  • 1. INSERT

3. 1.

RDMS Workflow Engine

slide-17
SLIDE 17

Append-only Log

1.

create workflow instance workflow instance created start event

  • ccured

sequence flow taken activity activated task created lock created task locked complete task task completed activity completed sequence flow taken …

2. 2. 1.

Workflow Engine

slide-18
SLIDE 18

Event Handling, Replication & Single Writer

Follower Follower

complete task command task completed event 1

send

2

append command

Broker (Leader)

Stream Processor 4

process

7

store & replicate event

6

append event

3

store & replicate command

5

respond Single Writer (single thread)

slide-19
SLIDE 19

What we do different

Follower Follower

complete task command task completed event 1

send

2

append command

Leader

Stream Processor 4

process

7

store & replicate event

6

append event

3

store & replicate command

5

respond Single Writer (single thread)

Store and replay commands Delete records that are fully processed Persist & replicate internal state

slide-20
SLIDE 20

Consistency Availability Partition

slide-21
SLIDE 21

Zeebe is CP

Follower Follower

complete task command task completed event 1

send

2

append command

Leader

Stream Processor 4

process

7

store & replicate event

6

append event

3

store & replicate command

5

respond Single Writer (single thread)

slide-22
SLIDE 22

Horizontal scalability by partitioning

Partition 1 Partition 2 Partition 3 Partition 4

Every workflow instance is exactly handled by one partition

instance id: 2-42 instance id: 3-66

Stream Processor Single Writer (single thread)

slide-23
SLIDE 23

Queries and read models

Zeebe Broker Zeebe Broker

Streaming Exporter ask ask

slide-24
SLIDE 24

Recap 1 – Events on the inside # Natural mechanism to build scalable services in distributed systems (with Outbox & co included) But # You have to think about reads, queries & eventual consistency # Few industry experience available

@berndruecker

slide-25
SLIDE 25

Service 1

Agenda

Service 2

Events on the inside Events on the outside

1 3

Events inside out

2

slide-26
SLIDE 26

Event Store and Messaging

Customer

  • 1. Create Customer

Customer Event Store

slide-27
SLIDE 27

Merge Messaging and Event Store

Customer

  • 1. Create Customer

Customer Event Store

slide-28
SLIDE 28

Merge messaging and event store

Customer

  • 1. Create Customer

Shared Event Store

slide-29
SLIDE 29

Enter the world of Kafka…

slide-30
SLIDE 30

Merge messaging and event store

Customer

  • 1. Create Customer

Shared Event Store

slide-31
SLIDE 31

Kafka as transport

Customer

  • 1. Create Customer

Used as queue (but persistent!)

slide-32
SLIDE 32

Kafka as transport

Customer

  • 1. Create Customer

Used as queue (but persistent!)

slide-33
SLIDE 33

Service 1

Agenda

Service 2

Events on the inside Events on the outside

1 3

Events inside out

2

slide-34
SLIDE 34

Once upon a time

Billing Customer

Change Address

slide-35
SLIDE 35

Event Notification

Address changed

Billing Customer

slide-36
SLIDE 36

Event Notification

Address changed

Billing Customer Billing Customer

Reverse direction

  • f dependency

What‘s direction

  • f dependency

Change Address

slide-37
SLIDE 37

Event Notification

Address changed

Billing Customer

AdressChanged { customerId: 42 } Ask for details

slide-38
SLIDE 38

Event-carried State T ransfer

Address changed

Billing Customer

AddressChanged { customerId: 42, address: ... } CustomerChanged { customerId: 42, status: A, address: ..., } AddressChanged { customerId: 42,

  • ldAddress: ...

newAddress: ... } CustomerMoved { ..., }

slide-39
SLIDE 39

This decision is complex

Address changed

Billing Customer Billing Customer

Reverse direction

  • f dependency

What‘s direction

  • f dependency

Change Address

slide-40
SLIDE 40

Example

Change Address Address Submit

From bla@company.com Date 2019-04-23 09.05 To confirm your address change please click on this link: http://company.com/confirm?id=82e97d49-166c-4862- 9973-4db348e6225d

Incoming Email

slide-41
SLIDE 41

Example

Customer Notification

Address change confirmed Change Adress Address change requested

http://company.com/confirm?id=82e97 d49-166c-4862-9973-4db348e6225d

direction of dependency

slide-42
SLIDE 42

Example

Customer Notification

‚Confirmation‘ approved Change Adress

http://company.com/confirm?id=82e97 d49-166c-4862-9973-4db348e6225d

Send mail ‚Confirmation‘ Address changed

direction of dependency

slide-43
SLIDE 43

Challenge: Command vs. Event

Event Command

vs

slide-44
SLIDE 44

It is NOT about communication protocols

Address changed

Billing Customer Billing Customer

Change Address

It can be messaging, REST, whatever, ….

slide-45
SLIDE 45

Manifold ways of transport

slide-46
SLIDE 46

Manifold ways of transport

slide-47
SLIDE 47

?

Event Command Query Message Record Event

Fact, happened in the past, immutable Intend, Want s.th. to happen, The intention itself is a fact

slide-48
SLIDE 48

?

Event Command Query Message Record Event

slide-49
SLIDE 49

Commands in disguise

The Customer Needs T

  • Be

Sent A Message T

  • Confirm

Address Change Event Send Message

Wording of Sender Wording of recipient

slide-50
SLIDE 50

Examples

Payment Order Subscription

Retrieve Payment More general, does not need to know who is retrieving payments

Customer Order

Address Changed

Billing

More general, does not need to care about who is interessted in address changes

Notification

Send Mail Global service

Order Notification

Order Placed Payment Received Goods Shipped Service that can handle notifications for orders autonomously

slide-51
SLIDE 51

Distributed Monoliths

Authorization Service Document Context Page Context

Document attached Page created Document moved Page moved

slide-52
SLIDE 52

Define stable contract/API instead

Authorization Service Document Context Page Context

Add auth

slide-53
SLIDE 53

Next challenge: Event chains

slide-54
SLIDE 54

Event Chains

Adress Check Credit Check Registration @berndruecker Customer

Event Bus

Registration requested Credit checked Address checked Customer registered

slide-55
SLIDE 55

Event Chains

Adress Check Credit Check Registration @berndruecker Customer

Event Bus

Registration requested Credit checked Address checked Customer registered

How does customer registration work?

slide-56
SLIDE 56

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-57
SLIDE 57

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-58
SLIDE 58

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-59
SLIDE 59

Monitoring Workflows Across Microservices

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

slide-60
SLIDE 60

T ypical approaches

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

slide-61
SLIDE 61

What we currently build with customers…

Camunda Optimize

Elastic Registration requested Credit checked Address checked Customer registered @berndruecker

slide-62
SLIDE 62

All great – until you have to move…

slide-63
SLIDE 63

Keep it stable, just move that

  • ne stick down there to the

top. How hard can it be?

slide-64
SLIDE 64

Changes required for an additional check

Adress Check Credit Check Registration Criminal Check @berndruecker Customer

Event Bus

Registration requested Credit checked Customer registered Address checked

slide-65
SLIDE 65

Changes required for an additional check

Adress Check Credit Check Registration Criminal Check @berndruecker Customer

Event Bus

Registration requested Credit checked Customer registered Address checked Criminal checked

slide-66
SLIDE 66

Alternative flow

Adress Check Credit Check Registration Criminal Check @berndruecker Customer

Kafka

Customer registered Registration requested Address checked Credit checked Criminal checked

slide-67
SLIDE 67

Alternative flow

Adress Check Credit Check Registration Criminal Check @berndruecker Customer

Kafka

Customer registered Registration requested Address checked Credit checked Criminal checked

„Credit checks got more expensive, do that only if all

  • ther checks succeed“
slide-68
SLIDE 68

What we wanted

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

slide-69
SLIDE 69

Orchestration

Address Check Credit Check Registration Customer

Kafka

Registration requested Credit checked Address checked Customer registered Check credit Check address @berndruecker

slide-70
SLIDE 70

Changes…

Address Check Credit Check Registration Customer

Kafka

Registration requested Credit checked Address checked Customer registered Check credit Check address @berndruecker Criminal Check Crimes checked Check crimes

slide-71
SLIDE 71

Coupling myths

@berndruecker

slide-72
SLIDE 72

Comparison

2 2 change nges criminal check can be deployed first 2 2 change nges, criminal check can be deployed first See also https://www.infoworld.com/article/3391592/ how-to-tame-event-driven-microservices.html @berndruecker

slide-73
SLIDE 73

Your IT architecture

Choreography Orchestration

@berndruecker

Your services

  • r applications
slide-74
SLIDE 74

Monolith Chaos Choreography Orchestration

@berndruecker

Process Monitoring

Your services

  • r applications
slide-75
SLIDE 75

Your IT architecture

Process Monitoring

Monolith Chaos Choreography Orchestration

Your services

  • r applications

Balance choreography and orchestration

@berndruecker

slide-76
SLIDE 76

In my world…

Customer On-boarding

Leverage Workflow Engine & BPMN within Service

slide-77
SLIDE 77

Customer

Local Orchestration

Central Orchestration Service

slide-78
SLIDE 78

Recap 2 # Commands vs. Events: Decide about the direction of dependencies # Beware of event-chains and avoid losing sight # Balance choreography and orchestration

@berndruecker

slide-79
SLIDE 79

Service 2 Service 1

Recap

Events on the inside Events on the outside

1 3

Persistent state vs persistent change Event sourcing & Event Store Consistency & CAP Read Models & CQRS Events as API Event vs Command Event chains & visibility Orchestration vs Choreography Shared Event Store

Events inside out

2

slide-80
SLIDE 80

Want to see code?

slide-81
SLIDE 81

Meet practicioners around orchestration & workflow April 23-24

Capital One, Cox Automotove, Nokia Bell Labs, Goldmann Sachs, … https://www.camundacon.com/

slide-82
SLIDE 82

Nothing for the faint of heart…

Events on the inside Events on the outside

slide-83
SLIDE 83

Nothing for the faint of heart…

…but doable… …and worth it

slide-84
SLIDE 84

Thank you!

@berndruecker

slide-85
SLIDE 85

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/