CQRS and ES with Lagom
-
Upload
miel-donkers -
Category
Software
-
view
339 -
download
6
Transcript of CQRS and ES with Lagom
1
CQRS & EVENTSOURCING
With Lagom
2 . 1
Miel Donkers@mieldonkers
github.com/mdonkers
@codecentric_nl
2 . 2
AgendaCQRS conceptsEvent Sourcing conceptsIntroduction Lagom frameworkCQRS & ES as basis for LagomLagom code / demo
3 . 1
What is CQRS
3 . 2
What is CQRSCommand Query Responsibility Segregation
3 . 3
Traditional Architecture
© Martin Fowler
3 . 4
CQRS Architecture
© Martin Fowler
3 . 5
Storing dataSimple approach
Single databaseNormalized tables for write-side dataViews for denormalizing dataKeep queries simple
3 . 6
CQRS related to DDDDDD - Domain Driven DesignBounded ContextAggregateCommandEvent
3 . 7
DDD example
3 . 8
Command - Event - State
3 . 9
Service owns data
4 . 1
What is ES
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.
4 . 3
CQRS & ES Combined
4 . 4
Architecture with Transactions
© Microsoft - CQRS Journey
4 . 5
Architecture with Messages
© Microsoft - CQRS Journey
4 . 6
The hard parts
4 . 7
ConsistencyKey feature for the Event StoreWithout transactions, much work needed to make asreliableVersioning / timestampsEventual consistency
4 . 8
Error HandlingDistinguish between business faults and errors.
Errors can be re-tried.Business faults should have pre-determinedreaction.
4 . 9
Other disadvantagesMany moving parts, makes it hard to debug thesystem as a wholeCQRS not for every bounded context
4 . 10
Advantages
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
5 . 1
Lagom microservice framework
5 . 2
Design philosophyDistributedAsynchronousProductivity
5 . 3
ConceptsMicroservicesPolyglotDesign Driven APIsImmutabilityEvent Sourcing and CQRS
5 . 4
OpiniatedServiceCall<Source<String, NotUsed>, Source<String, NotUsed>> stream();
@Overridedefault Descriptor descriptor() { return named("stream").withCalls(namedCall("stream", this::stream)) .withAutoAcl(true);}
5 . 5
Core technologiesAkka
Akka StreamsAkka PersistenceAkka Cluster
PlayConductR
5 . 6
Lagom persistenceCassandraPersistentEntity
Requires Command, Event and StateSingle instance kept in memory
5 . 7
Command - Event - State
5 . 8
5 . 8
5 . 9
Get me all inspections with remarks for a given ship
Query example
5 . 10
Lagom JDBC supportAvailable in 1.2 releaseSlickStoring and reading entities
6 . 1
CODE
6 . 27 . 1
Wrapping Up
7 . 2
Lessons learnedConventions make setup easyFramework on top of many layers
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>...
7 . 3
7 . 4
LinksMartin Fowler - CQRSMicrosoft - CQRS JourneyLagom FrameworkMiel Donkers - Lagom CQRS Demo
7 . 5
Thank You!
7 . 6
We're hiring