90
Opportunities & Pitfalls of Event-Driven Utopia @berndruecker

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

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

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

Opportunities & Pitfalls of Event-Driven Utopia

@berndruecker

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

Why this talk

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

Why this talk

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

Service 1

Agenda

Service 2

Events on the inside

Events on the outside

1

3

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

Service 1

Agenda

Service 2

Events on the inside

Events on the outside

1

3

Events inside out2

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

Service 1

Agenda

Service 2

Events on the inside1

Events on the outside3

Events inside out2

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

Once upon a time…

RDMS

Application

Client

BBC architecture(box - arrow – box – arrow - cylinder)

Every architecture diagramyou'll ever need

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

The great thing about this architecture

RDMS

Application

DB gurantees (e.g. ACID)

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

The problem

not webscaleresiliency is expensive

RDMS

Application

RDMS

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

Pat Helland

https://vimeo.com/52831373

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

Append-onlyLog

bankaccount 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 $

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

Append-onlyLog

bankaccount created

+2,500 $transfered

-14.99$paid by

credit card

Persistent change Event

Bank Account Created2019/04/16 11:00

# 12345

Event

Money Transfer Received2,500$

2019/04/16 11:00# 12345

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

Event Sourcing in a nutshell

Customer

BusinessLogic

Save event

2. Read events

Replay

Internal State

3. Buildinternal state

5. Add Customer Created Event

1. Create Customer 4. Validation and Invariant Checks

e.g. Customer Created, Customer Credit Limit Approved, …Customer Event Store

6. Async publishCustomer Created Domain Event

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

Working without distributed transactions

Customer

BusinessLogic

Save event

2. Read events

Replay

Internal State

3. Buildinternal state

5. Add Customer Created Event

1. Create Customer 4. Validation and Invariant Checks

e.g. Customer Created, Customer Credit Limit Approved, …Customer Event Store

6. Async publishCustomer Created Domain Event

This is the onlyatomic operation

required

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

Traditional Architecture

Customer

1. Create Customer

Account

RDMS

BusinessLogic

Open Account

2. Persist statechanges

3. Remote Communication

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

Pat Helland

Distributed Systems Guru Worked at Amazon, Microsoft & Salesforce

@berndruecker

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

Pat Helland

Grown-Ups Don’t Use Distributed Transactions

Distributed Systems Guru Worked at Amazon, Microsoft & Salesforce

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

Open Account

Outbox pattern in traditional architectures

Customer

1. Create Customer

Account

RDMS

BusinessLogic

Job: „Open

Account“

2. Persist statechanges

3. Remote CommunicationExecute:

„Open Account“

TX 1 TX 2

Async after firsttransaction!

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

Outbox pattern – Implementation Approaches

Scheduler

DatabaseTransaction Log

WorkflowAutomation

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

Idempotency

Customer

1. CreateCustomer

Account

RDMS

BusinessLogic

Job: „Open

Account“

2. Persist statechanges

3. Remote Communication

Async after transaction!

Execute: „Open

Account“

CaptureRequest

TX 1 TX 2

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

Idempotency

Customer

1. CreateCustomer

Account

RDMS

BusinessLogic

Job: „Open

Account“

2. Persist statechanges

3. Remote Communication

Async after transaction!

Execute: „Open

Account“

CaptureRequest

TX 1 TX 3TX 2

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

Working without distributed transactions

Customer

BusinessLogic

Save event

2. Read events

Replay

Internal State

3. Buildinternal state

5. Add Customer Created Event

1. Create Customer 4. Validation and Invariant Checks

e.g. Customer Created, Customer Credit Limit Approved, …Customer Event Store

6. Async publishCustomer Created Domain Event

This is the onlyatomic operation

required

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

Events on the inside. An example from my world

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

[email protected]@berndruecker

Bernd RueckerCo-founder and Chief Technologist ofCamunda

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

We offer two different workflow engines. Why?

Camunda ZeebePersistent State

Persistent change

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

WorkflowInstanceId

CurrentActivity

State

2 RetrievePayment running

WorkflowInstanceId

CurrentActivity

State

2 ShipGoods running

WorkflowInstanceId

CurrentActivity

State

2 OrderDelivered ended

2.

3. UPDATE

2. UPDATE

1. INSERT

3.1.

RDMS

Workflow Engine

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

Append-onlyLog1.

createworkflowinstance

workflowinstancecreated

startevent

occured

sequenceflow taken

activityactivated

taskcreated

lockcreated

tasklocked

completetask

taskcompleted

activitycompleted

sequenceflow taken

2.

2.1.

Workflow Engine

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

Event Handling, Replication & Single Writer

FollowerFollower

complete taskcommand

task completedevent

1 send

2 append command

Broker (Leader)

StreamProcessor

4 process

7store & replicateevent6 append event

3store & replicatecommand

5 respond

Single Writer(single thread)

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

What we do different

FollowerFollower

complete taskcommand

task completedevent

1 send

2 append command

Leader

StreamProcessor

4 process

7store & replicateevent6 append event

3store & replicatecommand

5 respond

Single Writer(single thread)

Store and replaycommands

Delete records thatare fully processed

Persist & replicateinternal state

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

ConsistencyAvailabilityPartition

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

Zeebe is CP

FollowerFollower

complete taskcommand

task completedevent

1 send

2 append command

Leader

StreamProcessor

4 process

7store & replicateevent6 append event

3store & replicatecommand

5 respond

Single Writer(single thread)

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

Horizontal scalability by partitioning

Partition 1

Partition 2

Partition 3

Partition 4

Every workflow instance isexactly handled by onepartition

instance id: 2-42

instance id: 3-66

StreamProcessor Single Writer

(single thread)

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

Queries and read models

ZeebeBroker

ZeebeBroker

StreamingExporter

ask

ask

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

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# Much less industry experience available

@berndruecker

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

Service 1

Agenda

Service 2

Events on the inside

Events on the outside

1

3

Events inside out2

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

Event Store and Messaging

Customer

1. Create Customer

Customer Event Store

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

Merge Messaging and Event Store

Customer

1. Create Customer

Customer Event Store

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

Merge messaging and event store

Customer

1. Create Customer

Shared Event Store

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

Enter the world of Kafka…

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

Merge messaging and event store

Customer

1. Create Customer

Shared Event Store

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

Kafka as transport

Customer

1. Create Customer

Used as queue (but persistent!)

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

Service 1

Agenda

Service 2

Events on the inside

Events on the outside

1

3

Events inside out2

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

Once upon a time

Billing

Customer

Change Address

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

Event Notification

Addresschanged

Billing

Customer

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

Event Notification

Addresschanged

Billing

Customer

Billing

Customer

Reverse directionof dependency

What‘sgeneral

WhichWho direction

of dependency

ChangeAddress

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

Event Notification

Addresschanged

Billing

Customer AdressChanged{

customerId: 42 }

Ask for details

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

Event-carried State Transfer

Addresschanged

Billing

Customer

AddressChanged{ customerId: 42,address: ...

}

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

}

AddressChanged{ customerId: 42,oldAddress: ...newAddress: ...

}

CustomerMoved{ ...,}

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

This decision is complex

Addresschanged

Billing

Customer

Billing

Customer

Reverse directionof dependency

What‘sgeneral

WhichWho direction

of dependency

ChangeAddress

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

Example

Change Address

Address

SubmitFrom [email protected]

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

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

Example

Customer

Notification

Address changeconfirmed

Change AdressAddress change

requested

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

direction of dependency

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

Example

Customer

Notification

‚Confirmation‘ approved

Change Adresshttp://company.com/confirm?id=82e97d49-166c-4862-9973-4db348e6225d

Send mail ‚Confirmation‘

Addresschanged

direction of dependency

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

Challenge:Command vs. Event

Event

Command

vs

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

It is NOT about communication protocols

Addresschanged

Billing

Customer

Billing

Customer

ChangeAddress

It can be messaging, REST, whatever, ….

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

Manifold ways of transport

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

Manifold ways of transport

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

?

Event Command Query

Message Record Event

Fact, happened in the past, immutable

Intend, Want s.th. to happen,The intention itself is a fact

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

?

Event Command Query

Message Record Event

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

Commands in disguise

The Customer Needs To Be Sent A Message To Confirm

Address ChangeEvent

Send Message

Wording ofSender

Wording ofrecipient

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

Examples

PaymentOrder

Subscription

RetrievePayment

More general,does not need to know

who is retrieving paymentsCustomer

Order

AddressChanged

Billing

More general,does not need to care about

who is interessted in address changes

Notification

SendMail

Global service

OrderNotification

OrderPlaced

PaymentReceived

Goods Shipped

Service that canhandle notifications

for ordersautonomously

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

Distributed MonolithsAuthorization

Service

Document Context PageContext

Document attached

Pagecreated

Document moved

Page moved

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

Define stable contract/API insteadAuthorization

Service

Document Context PageContext

Add auth

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

Next challenge:Event chains

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

Event Chains

AdressCheck

Credit Check

Registration

@berndruecker

Customer

Event BusRegistration

requestedCredit

checkedAddresschecked

Customer registered

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

Event Chains

AdressCheck

Credit Check

Registration

@berndruecker

Customer

Event BusRegistration

requestedCredit

checkedAddresschecked

Customer registered

How does customerregistration work?

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

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

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

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

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

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

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

Monitoring Workflows Across Microservices

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

@berndruecker

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

Typical approachesDistributed Tracing

Data Lake / Event Monitoring

Process Mining

Process Tracking

@berndruecker

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

What we currently build with customers…

CamundaOptimize

ElasticRegistration

requestedCredit

checkedAddresschecked

Customer registered

@berndruecker

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

All great – until you have to move…

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

Changes required for an additional check

AdressCheck

Credit Check

Registration

CriminalCheck

@berndruecker

Customer

Event BusRegistration

requestedCredit

checkedCustomer registered

Addresschecked

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

Changes required for an additional check

AdressCheck

Credit Check

Registration

CriminalCheck

@berndruecker

Customer

Event BusRegistration

requestedCredit

checkedCustomer registered

Addresschecked

Criminalchecked

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

Alternative flow

AdressCheck

Credit Check

Registration

CriminalCheck

@berndruecker

Customer

Kafka Customer registered

Registration requested

Addresschecked

Creditchecked

Criminalchecked

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

Alternative flow

AdressCheck

Credit Check

Registration

CriminalCheck

@berndruecker

Customer

Kafka Customer registered

Registration requested

Addresschecked

Creditchecked

Criminalchecked

„Credit checks got moreexpensive, do that only if all

other checks succeed“

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

Keep it stable, just movesticks with yellow color to the

top.

How hardcan it be?

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

Orchestration

AdressCheckCredit Check

Registration

Customer

KafkaRegistration

requestedCredit

checkedAddresschecked

Customer registeredCheck

credit

Check address

Customer checked

CustomerOn-boarding

Of course these twoservices could be merged

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

Changes

AdressCheckCredit Check

Registration

Customer

KafkaRegistration

requestedCredit

checkedAddresschecked

Customer registeredCheck

credit

Check address

Customer checked

CustomerOn-boarding

Criminal Check

Crimes checked

Check crimes

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

Comparison2 changescriminal check can be deployed first

2 changes, criminal check can be deployed first

See also https://www.infoworld.com/article/3391592/how-to-tame-event-driven-microservices.html

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

In my world…

CustomerOn-boarding

Leverage Workflow Engine & BPMN within Service

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

Customer On-boarding

Local Orchestration

CentralOrchestration

Service

Page 83: Opportunities & Pitfalls Event-Driven UtopiaEvent-Driven Utopia @berndruecker Why this talk Why this talk Service 1 Agenda Service 2 Events on the inside Events on the outside 1 3
Page 84: Opportunities & Pitfalls Event-Driven UtopiaEvent-Driven Utopia @berndruecker Why this talk Why this talk Service 1 Agenda Service 2 Events on the inside Events on the outside 1 3

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

@berndruecker

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

Service 2Service 1

Recap

Events on the inside

Events on the outside

1

3

Persistent state vs persistent changeEvent sourcing & Event StoreConsistency & CAPRead Models & CQRS

Events as APIEvent vs CommandEvent chains & visibilityOrchestration vs Choreography

Shared Event Store

Events inside out2

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

Want to see code?

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

Nothing for the faint of heart…Events on the inside

Events on the outside

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

Nothing for the faint of heart…

…but doable…

…and worth it

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

Thank you!

@berndruecker

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

[email protected]@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/