orchestration of microservices - java forum stuttgart · orchestration of microservices...

67
Orchestration of Microservices [email protected] With thoughts from http:// flowing.io @berndruecker | @martinschimak

Upload: dangnhi

Post on 12-Aug-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Orchestration of Microservices

[email protected]

With thoughts from http://flowing.io@berndruecker | @martinschimak

Page 2: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

AT&T

Page 3: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Microservoices?

Page 4: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

https://www.flickr.com/photos/12567713@N00/310639290

Page 5: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Microservices

• Independent components

• Independent deployments

• Decoupling between components

• Dedicated teams to fight conways law

• Autonomy of technology decisions

• Avoid horizontal team boundaries

• New DevOps paradigms

Microservice

Microservice

Microservice

Monolith

A

B

C

A

B

C

Page 6: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Increasingcomplexityof relation-

ships

Page 7: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Event-Driven Microservices

Microservice Microservice

A B

Event

event namepayload

no receipient

Page 8: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Event-Driven Microservices

Microservice Microservice

A B

Event

Does not know

about B

Does not know

about A

Page 9: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Isn‘t that SOA?

Service Service

A B

ESB

Page 10: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

It is not SOA

Service Service

A B

ESB

„smart endpoints and dumb pipes”

Page 11: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Disclaimer: I do not advertise event-drivenmicroservices as silver bullet!

Only use it when appropriate.Handle with care!

Page 12: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Distributed systems

Page 13: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

You need some safe harbors and strategies to sail the wild ocean

Page 14: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Microservices Event Driven & Reactive Domain Driven Design

Page 15: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Let‘s do an example!

Assume you wantto build a Dash button.

Page 16: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

pay receive

shipment

place

order

I want to have

one item!

I am happy!

Page 17: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Business Capabilities

BoundedContexts= Microservices

Order placed

Shop Payment Shipping

BusinessOutputs / Domain Events

Inventory

Payment received

Goodsfetched

Goodsshipped

Page 18: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Collaboration using an eventflow

Order placed

Payment received

Goodsfetched

Goodsshipped

InventoryPayment ShippingShop

Page 19: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Great!

Page 20: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Great?

Page 21: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Let‘s zoom in the payment context

PaymentOrder placed

Payment received

Page 22: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Let‘s zoom in the payment context

PaymentOrder placed

Payment received

The payment contexthas to listen to

„order placed“ event

Page 23: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

De-coupling?

Payment

Orderplaced

Servicefullfilled

Whenever a new client requirespayment, the payment contexthas to be touched

The payment context has to knowall possible events that trigger a payment

Subscriptionconfirmed

Page 24: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Event command transformation

PaymentRetrievepayment

Orderplaced Transformation

CommandSomething has to happenin the future1 recipient

EventSomething has happendin the past0..n recipients

Page 25: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Order context

PaymentRetrievepayment

Orderplaced Order

Page 26: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Event vs. command

PaymentRetrievepayment

Orderplaced Order

decide where todo the coupling

Page 27: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Business Capabilities

Order placed

Shop Payment ShippingInventory

Payment received

Goodsfetched

Goodsshipped

Order

Order completed

Retrievepayment

Fetchgoods

Shipgoods

Page 28: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Quality Criteria: Changability

VIP customers can order with invoice (and pay later)

Page 29: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Changability with pure event-chain

Order placed

Payment received

Goodsfetched

Goodsshipped

InventoryPayment ShippingShop

If VIP customer

If not VIP customer

Order billed

Billing

If VIP customer

VIP customers can order with invoice (and pay later)

Page 30: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Changability with Event Command Transformation

Order placed

Shop Payment ShippingInventory

Payment received

Goodsfetched

Goodsshipped

Order

Order completed

VIP customers can order with invoice (and pay later)

Change howto issue

commands

Page 31: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Quick demo

http://github.com/flowing/

Page 32: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Now back to real-life

Page 33: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Some things in live might be slow

Payment

Retrievepayment

Orderplaced Order

Paymentretrieved

Page 34: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Long running flowsrequire persistent state

Page 35: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

How to implement?

Page 36: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

State in entity

More alternatvies in my blog: https://blog.bernd-ruecker.com/how-to-implement-long-running-flows-sagas-business-processes-or-similar-3c870a1b95a8

Page 37: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

The 7 sins of workflow

3

2

4

6

5

7

1

http://blog.bernd-ruecker.com/

Page 38: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

The 7 sins of workflow

3

4

6

5

7

http://blog.bernd-ruecker.com/

No state machine

Homegrownstate machine

Page 39: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Think about subsequent requirements

Monitoring & Operations

Visibility

VersioningTime &

Timeouts

Domain Language

Performance & Scaling

Page 40: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Process Manager

• Do event command transformation

• Handle state for long running flows

Page 41: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

State machine http://camunda.org/

Page 42: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Logic remains in normal code

Page 43: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Tools provide persistent state, visibility and much more

+

Page 44: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

On top: visbility

PaymentRetrievepayment

Orderplaced Order

Page 45: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Martin Fowler

Event notification is nice because it implies a low level of coupling, and is pretty simple to set up. It can become problematic, however, if there really is a logical flow that runs over various event notifications. The problem is that it can be hard to see such a flow as it's not explicit in any program text. Often the only way to figure out this flow is from monitoring a live system. This can make it hard to debug and modify such a flow. 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

Page 46: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Smells like „BPM“?

Page 47: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

The 7 sins of workflow

Homegrownengine

BPM monolith

No engine Wrong engine Wrong usage

http://blog.bernd-ruecker.com/

4 5

7

3

Page 48: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

The end-to-end process?

Page 49: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Don‘t do a „BPM monolith“ when using Microservices!

Order Feedback

InventoryPayment

Page 50: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Pa

yme

nt

Local flows in the bounded contextsO

rde

r

Page 51: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Multiple engines

Payment

Order

engine

engine

Inventory

Shipping

engine

Page 52: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

The 7 sins of workflow

Zero-code suites

Homegrownengine

No engine Wrong engine Wrong usage

4 5

7

http://blog.bernd-ruecker.com/

BPM monolith

Page 53: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Death by properties panel

Script:

Please enter your complex code here. (Without IDE support of course!)

Page 54: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Bernd Rücker

Consultant & Evangelist10+ years workflow

http://bernd-ruecker.com/[email protected]

Co-founder Camundahttp://camunda.org/

Page 55: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak
Page 56: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Define flows programatically or graphically

Page 57: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Productive development and testing

Page 58: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Developer friendly

Page 59: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Big challenges for developers ahead!

Page 60: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Error and timeout handling

Page 61: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Handling complex scenarios

Page 62: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Demo

http://github.com/flowing/

Page 63: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Demo architecture

InventoryPaymentOrder Shipping

H2

Shop Monitor

Camunda Webapp

on Tomcat

for demo in single Java VM for simplicity

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

Page 64: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Lightweight state machines orworkflow engines are not evil!

They do help you solving some reallyhard coding problems.

These problems become more and more frequent every day.

Page 65: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

https://www.infoq.com/articles/microservice-event-choreographies

Page 66: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Code online:https://github.com/flowing

Slides online:http://bernd-ruecker.com

Feedback:http://bernd-ruecker.com/feedback

With thoughts from http://flowing.io@berndruecker | @martinschimak

Page 67: Orchestration of Microservices - Java Forum Stuttgart · Orchestration of Microservices bernd.ruecker@camunda.com With thoughts from  @berndruecker | @martinschimak

Thank you!