pragmatic event driven microservices - goto conference · event-driven microservices ... data...

56
@allardbz Event-Driven Microservices Not (just) about events Allard Buijze Founder & CTO, AxonIQ [email protected] @allardbz

Upload: others

Post on 28-May-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Event-Driven MicroservicesNot (just) about events

Allard BuijzeFounder & CTO, AxonIQ

[email protected]@allardbz

Page 2: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Layered architectureUser Interface

Service Layer

Data Access Layer

Dom

ain Model

Page 3: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Service

Service

Service

Page 4: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

‘Normal’ SQL QUERY

22 JOINS 6 SUBQUERIES

Page 5: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Layered architectureUser Interface

Service Layer

Data Access Layer

Dom

ain Model

Method invocation Cache

Worker pools

Web Cache

Session replication

Distributed 2nd level cache Query Cache

Page 6: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Page 7: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Source: http://www.sabisabi.com/images/DungBeetle-on-dung.JPG

Page 8: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Microservices systems• Splitting up systems into smaller,

simpler components• Agility• Scalability

Page 9: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Are you tall enough?

Source: martinfowler.com/bliki/MicroservicePrerequisites.html

Page 10: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Microservices vs Monoliths

Microservices system Almost all the cases where I've heard of a system that was built as a microservice system from scratch, it has ended up in serious trouble.

Monoliths Almost all the successful microservice stories have started with a monolith that got too big and was broken up

Martin Fowler

Source: http://martinfowler.com/bliki/MonolithFirst.html

Page 11: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

“Noun Driven Design”

Noun? ! Service!

Page 12: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

“Noun Driven Design”

OrderService

Page 13: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

“Noun Driven Design”

CustomerService

Page 14: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

“Noun Driven Design”

ProductService

Page 15: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

“Noun Driven Design”

InventoryService

Page 16: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

“Entity Services”

Page 17: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Command Query Responsibility Segregation

Command model

Projections

Client

Events

T: 1 mln / s Resp: < 10 ms

T: Thr. 20 / s Resp: < 100 ms

T: 10 mln / s Resp. < 100 ms

T: 1 / s Resp. < 10 ms

Page 18: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

?

Page 19: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Monoliths

St Breock Downs Monolith - www.cornwalls.co.uk

Page 20: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

$

Page 21: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Location transparency

A Component should not be aware, nor make any assumptions, of the location of Components it

interacts with

A component should neither be aware of nor make any assumptions about the location of components it interacts with.

Location transparency starts with good API design (but doesn’t end there)

Page 22: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

‘Event-Driven’ Microservices

“Event” all the things!

Page 23: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

‘Event-Driven’ Microservices

Maslow’s Hammer

Page 24: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

‘Event-Driven’ Microservices

Birmingham Screwdriver

Page 25: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

‘Event-Driven’ Microservices

“Maslow Syndrome”

Page 26: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

‘Event-Driven’ Microservices

Need to know ordered itemsOrder service

OrderCreated !

ItemAdded !

ItemRemoved !

OrderConfirmed !

Page 27: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Or worse…

Shipping ServiceOrder service

OrderCreated !

" InventoryConfirmed

ReadyForShipping !

" OrderShipped

Payment service

OrderPaid !

" ReadyForPayment

Page 28: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Microservices MessagingCommands Events Queries

Route to single handlerUse consistent hashing

Provide result

Distribute to all logical handlersConsumers express ordering req’s

No results

Route with load balancingSometimes scatter/gather

Provide result

"Event" and “Message" is not the same thing

Page 29: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

OrderConfirmed !

‘Event-Driven’ Microservices

Need to know ordered itemsOrder service

ItemAdded !

ItemRemoved !

OrderConfirmed !

OrderCreated !

" GetOrderDetails

OrderDetails !

Page 30: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Or…

Shipping ServiceOrder service

ReserveInventory !

" InventoryReserved

ShipOrder !

" OrderShipped

Payment service

OrderPaid !

" PerformPayment

Page 31: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Events retain valueEvent Sourcing is an Architectural pattern in which Events are considered the “source of truth”, based on which components (re)build their internal state.

Page 32: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Event Sourcing

Some smart analyticsOrder service

OrderCreated !

ItemAdded !

ItemRemoved !

OrderConfirmed !

Page 33: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Event StoreAn Event Store stores the published events to be retrieved both by consumers as well as the publishing component itself.

Page 34: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Event Store operations• Append• Validate ‘sequence’

Page 35: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Event Store operations• Full sequential read

Page 36: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Event Store operations• Read aggregate’s events

Page 37: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

1. Consider explicit messages

2. Define which routing patterns to apply

3. Choose technology/protocol accordingly

Page 38: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Page 39: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Exchange

Queue

Queue

Event Store

Page 40: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Exchange

Queue

Queue

Event Store

Queue

Page 41: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

“Just enough” intelligence

dumb smart

Message Broker Sends messages. Main value add is reliability.

Enterprise Service Bus Understands message

content. Hard to configure and maintain.

Ideal middle ground ? Understands difference between Commands,

Events, Queries and their routing patterns. Does not care about the content of these

messages.

Page 42: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Exchange

Queue

Queue

Event Store

Queue

Page 43: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Page 44: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Evolutionary microservices

Commands Events Queries

Page 45: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

I can do:GetOrderDetailsCreateOrder…ConfirmOrder

I want to get some order details

Page 46: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

I can do:CreateOrder…ConfirmOrder

I can do:GetOrderDetailsI want to get some

order details

Page 47: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

At scale, different rules apply

Page 48: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

How do you route all these events to all components? How will this scale?

Page 49: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

You Don't! It Won't!

Page 50: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Unmanageable messOrder Created Item Added to Order Shipping Address Added Billing Address Added Order Confirmed

As shipping module, I want to

know when an order is placed

Page 51: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Communication = Contract

Page 52: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Bounded contextExplicitly define the context within which a model applies. Explicitly set boundaries in terms of team organization, usage within specific parts of the application, and physical manifestations such as code bases and database schemas. Keep the model strictly consistent within these bounds, but don’t be distracted or confused by issues outside.

Page 53: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Within a context, share ‘everything’

Page 54: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Between contexts, share ‘consciously’As shipping

module, I want to know when an order is placed

Order Created Item Added to Order Shipping Address Added Billing Address Added Order Confirmed

Order Confirmed + Get Order Details ! Order Placed

Page 55: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

Recap• Events are useful

• Don’t forget about Commands and Queries• Events retain value

• Modelling messages explicitly stimulates location transparency• Beware coupling• Consider Bonded Contexts

• “Evolve” your way into microservices

Page 56: Pragmatic Event Driven Microservices - GOTO Conference · Event-Driven Microservices ... Data Access Layer l. @allardbz Service Service Service. @allardbz ‘Normal’ SQL QUERY 22

@allardbz

References• Axon

• axoniq.io• github.com/axonframework• github.com/axoniq• @axonframework• @axoniq

• QuickStart: axoniq.io/download