distributed architecture patterns cqrs & event...
TRANSCRIPT
© Copyright 2010 Imaginet. All rights reserved.
Distributed Architecture Patterns
CQRS & Event Sourcing
© Copyright 2010 Imaginet. All rights reserved.
Dylan SmithSenior ALM Consultant
Application Lifecycle Expert
PROFILEDylan is an ALM (Application Lifecycle Management) consultant for Imaginet where he spends his time helping teams become more successful at delivering software. Dylan has over a decade experience designing and architecting mission critical applications. In the past 5 years Dylan has focused on agile development techniques and practices. He has led the shift to agile and lean development practices across multiple teams, projects and companies.
“CQRS+ES differs from most design patterns in that it provides clear business benefits in addition to the obvious technical benefits.”
© Copyright 2010 Imaginet. All rights reserved.
Overview• Review Typical
Architecture• What is CQRS?• What is Event Sourcing?• CODE !!!• Benefits / Concerns
© Copyright 2010 Imaginet. All rights reserved.
Data StorageData Storage
Domain Object
Domain Object
Application ServicesApplication Services
Remote FacadeRemote Facade
ClientClient
Request DTODTO ReturnedRequest DTODTO Returned
Send DTOStatus Returned
Send DTOStatus Returned
RepositoryRepository
Domain ObjectDomain Object
Typical Distributed Architecture
© Copyright 2010 Imaginet. All rights reserved.
Data StorageData Storage
Domain ObjectDomain Object
Command HandlersCommand Handlers
Remote FacadeRemote Facade
ClientClient
Request DTODTO
Returned
Request DTODTO
Returned
Send CommandAck/Nak
Response
Send CommandAck/Nak
Response
RepositoryRepository
Domain ObjectDomain Object
Query HandlersQuery Handlers
Remote FacadeRemote Facade
Data StorageData Storage
CQRS
© Copyright 2010 Imaginet. All rights reserved.
Sample Read Data Model
© Copyright 2010 Imaginet. All rights reserved.
Purchase Order
Purchase Order
Line Items (n)Line Items (n)
Shipping InformationShipping
Information
© Copyright 2010 Imaginet. All rights reserved.
Order CreatedOrder
CreatedAdded 4
HatsAdded 4
HatsAdded 2
ShirtsAdded 2
Shirts
Shipping Info
Added
Shipping Info
Added
© Copyright 2010 Imaginet. All rights reserved.
Event StoreEvent Store
Domain ObjectDomain Object
Command HandlersCommand Handlers
Remote FacadeRemote Facade
ClientClient
Request DTODTO
Returned
Request DTODTO
Returned
Send CommandAck/Nak
Response
Send CommandAck/Nak
Response
RepositoryRepository
Domain ObjectDomain Object
Query HandlersQuery Handlers
Remote FacadeRemote Facade
Data StorageData StorageEvent BusEvent Bus
CQRS + ES
Event
HandlersE
vent H
andlers
© Copyright 2010 Imaginet. All rights reserved.
Event Store Data Model
© Copyright 2010 Imaginet. All rights reserved.
© Copyright 2010 Imaginet. All rights reserved.
Command
© Copyright 2010 Imaginet. All rights reserved.
Event
© Copyright 2010 Imaginet. All rights reserved.
Command Handler
© Copyright 2010 Imaginet. All rights reserved.
Domain Object
© Copyright 2010 Imaginet. All rights reserved.
Event Handler
© Copyright 2010 Imaginet. All rights reserved.
Query Handler
© Copyright 2010 Imaginet. All rights reserved.
Data Transfer Object
© Copyright 2010 Imaginet. All rights reserved.
Scalability
© Copyright 2010 Imaginet. All rights reserved.
© Copyright 2010 Imaginet. All rights reserved.
© Copyright 2010 Imaginet. All rights reserved.
Sample Unit Test
© Copyright 2010 Imaginet. All rights reserved.
Sample Unit Test #2
© Copyright 2010 Imaginet. All rights reserved.
© Copyright 2010 Imaginet. All rights reserved.
© Copyright 2010 Imaginet. All rights reserved.
ClientClient
DomainDomain Read ModelRead Model
Events
Commands DTOs
© Copyright 2010 Imaginet. All rights reserved.
© Copyright 2010 Imaginet. All rights reserved.
NoSQL Databases
© Copyright 2010 Imaginet. All rights reserved.
Other Topics(Time Permitting)• Event Versioning• When to use CQRS/ES?• Using CQRS or ES separately• Concurrency• Eventual Consistency• Asynchronous Commands
© Copyright 2010 Imaginet. All rights reserved.
Recommended Reading
© Copyright 2010 Imaginet. All rights reserved.
Sample CodeSuper Simple CQRS Example
github.com/gregoryyoung/m-rNCQRS
ncqrs.orgThe CQRS Kitchen
thecqrskitchen.codeplex.comLokad-CQRS
code.google.com/p/lokad-cqrsFohjin
github.com/MarkNijhof/Fohjin
© Copyright 2010 Imaginet. All rights reserved.
SummaryCQRS – Enables specialization:
of design/architecture, and people
Event Sourcing – All about capturing intent and not losing data