cqrs and es with lagom

40
1 CQRS & EVENT SOURCING With Lagom

Upload: miel-donkers

Post on 16-Apr-2017

339 views

Category:

Software


6 download

TRANSCRIPT

Page 1: CQRS and ES with Lagom

1

CQRS & EVENTSOURCING

With Lagom

Page 2: CQRS and ES with Lagom

2 . 1

Miel Donkers@mieldonkers

github.com/mdonkers

 

@codecentric_nl

Page 3: CQRS and ES with Lagom

2 . 2

AgendaCQRS conceptsEvent Sourcing conceptsIntroduction Lagom frameworkCQRS & ES as basis for LagomLagom code / demo

Page 4: CQRS and ES with Lagom

3 . 1

What is CQRS

Page 5: CQRS and ES with Lagom

3 . 2

What is CQRSCommand Query Responsibility Segregation

Page 6: CQRS and ES with Lagom

3 . 3

Traditional Architecture

© Martin Fowler

Page 7: CQRS and ES with Lagom

3 . 4

CQRS Architecture

© Martin Fowler

Page 8: CQRS and ES with Lagom

3 . 5

Storing dataSimple approach

Single databaseNormalized tables for write-side dataViews for denormalizing dataKeep queries simple

Page 9: CQRS and ES with Lagom

3 . 6

CQRS related to DDDDDD - Domain Driven DesignBounded ContextAggregateCommandEvent

Page 10: CQRS and ES with Lagom

3 . 7

DDD example

Page 11: CQRS and ES with Lagom

3 . 8

Command - Event - State

Page 12: CQRS and ES with Lagom

3 . 9

Service owns data

Page 13: CQRS and ES with Lagom

4 . 1

What is ES

Page 14: CQRS and ES with Lagom

4 . 2

What is ESEvent SourcingEvent describes the state change of aggregateEvent is saved in event storeEvents can be replayed to re-create the current state.

Page 15: CQRS and ES with Lagom

4 . 3

CQRS & ES Combined

Page 16: CQRS and ES with Lagom

4 . 4

Architecture with Transactions

© Microsoft - CQRS Journey

Page 17: CQRS and ES with Lagom

4 . 5

Architecture with Messages

© Microsoft - CQRS Journey

Page 18: CQRS and ES with Lagom

4 . 6

The hard parts

Page 19: CQRS and ES with Lagom

4 . 7

ConsistencyKey feature for the Event StoreWithout transactions, much work needed to make asreliableVersioning / timestampsEventual consistency

Page 20: CQRS and ES with Lagom

4 . 8

Error HandlingDistinguish between business faults and errors.

Errors can be re-tried.Business faults should have pre-determinedreaction.

Page 21: CQRS and ES with Lagom

4 . 9

Other disadvantagesMany moving parts, makes it hard to debug thesystem as a wholeCQRS not for every bounded context

Page 22: CQRS and ES with Lagom

4 . 10

Advantages

Page 23: CQRS and ES with Lagom

4 . 11

AdvantagesAuditing and historical tracingRead and write side can be optimized separatelyDebug in local environmentSmall components which are easy to update / fixNo ORM impedance mismatch

Page 24: CQRS and ES with Lagom

5 . 1

Lagom microservice framework

Page 25: CQRS and ES with Lagom

5 . 2

Design philosophyDistributedAsynchronousProductivity

Page 26: CQRS and ES with Lagom

5 . 3

ConceptsMicroservicesPolyglotDesign Driven APIsImmutabilityEvent Sourcing and CQRS

Page 27: CQRS and ES with Lagom

5 . 4

OpiniatedServiceCall<Source<String, NotUsed>, Source<String, NotUsed>> stream();

@Overridedefault Descriptor descriptor() { return named("stream").withCalls(namedCall("stream", this::stream)) .withAutoAcl(true);}

Page 28: CQRS and ES with Lagom

5 . 5

Core technologiesAkka

Akka StreamsAkka PersistenceAkka Cluster

PlayConductR

Page 29: CQRS and ES with Lagom

5 . 6

Lagom persistenceCassandraPersistentEntity

Requires Command, Event and StateSingle instance kept in memory

Page 30: CQRS and ES with Lagom

5 . 7

Command - Event - State

Page 31: CQRS and ES with Lagom

5 . 8

Page 32: CQRS and ES with Lagom

5 . 8

5 . 9

Get me all inspections with remarks for a given ship

Query example

Page 33: CQRS and ES with Lagom

5 . 10

Lagom JDBC supportAvailable in 1.2 releaseSlickStoring and reading entities

Page 34: CQRS and ES with Lagom

6 . 1

CODE

Page 35: CQRS and ES with Lagom

6 . 27 . 1

Wrapping Up

Page 36: CQRS and ES with Lagom

7 . 2

Lessons learnedConventions make setup easyFramework on top of many layers

Page 37: CQRS and ES with Lagom

7 . 3

...[INFO] Service locator is running at http://localhost:8000[INFO] Service gateway is running at http://localhost:9000...[INFO] (Service started, press enter to stop and go back to the console...)[error] c.l.l.i.s.ServiceRegistrationModule$RegisterWithServiceRegistry - Service name=[hello] couldn't register itself to the service locator.com.lightbend.lagom.javadsl.api.transport.TransportException: <head>...[error] a.c.s.PersistentShardCoordinator - Persistence failure when replaying events for persistenceId [/sharding/HelloEntityCoordinator]. Last known sequence number [0]com.lightbend.lagom.javadsl.api.transport.PolicyViolation: <head>...

Page 38: CQRS and ES with Lagom

7 . 3

7 . 4

LinksMartin Fowler - CQRSMicrosoft - CQRS JourneyLagom FrameworkMiel Donkers - Lagom CQRS Demo

Page 39: CQRS and ES with Lagom

7 . 5

Thank You!

Page 40: CQRS and ES with Lagom

7 . 6

We're hiring