Preface
Very good I got a chance to attend the DevTeach 2012 at Vancouver. Even though I only get one day to be there, I am still so happy that we will see what other company are going in Architecture level.
First I must say thanks to those excellent speakers to show my respect:
Rob Daigneau
Dylan Smith
Ted Neward
Vincent Grondin
This blog is what I learned form Dylan, and the same time added some my thought to make it better in my opinion.
Content
1. What is CQRS
It stands as Command Query Responsibility Segregation
Strong point:
The core concepts is split write and read behavior to Command Handler and Query Handler, and it is really good to increase scalability for our server.
Imagine, a cluster which have 2 writing server and 20 read server based on 10 database, we can easily make it.
Weak point:
Command/Query handler is easy to implements, but it less extensibility and flexibility for reuse existing under layer modules. For examples: we want detect a behavior if user did command A, and then B, then D, we should do some specific thing for the case.
2. Event Sourcing
We all know the best benefit for Event-driven is we have flexibility and extensibility to hook up new features into the existing software. Based on CQRS's major weakness, we know if we mix this 2 architecture style together, we will have a round result.
3. CQRS + Event Sourcing
Based on Dylan's model, I added some specific part(red circle) in bellow overall figure:
|
Architecture illustrate for CQRS+ES |
Core classes:
CommandHandler
Queryhandler
DomainObject
Repository
Subscriber
EventHandler
DTO
I do not have time to write a small prototype for this, but I believe it is is good to deal with a large scale system.
4 Benifits
- Simple
- E=mc^2. Everything should be made as simple as possible, not simpler. In this architecture design, a new feature we can easily implement a bunch of classes, e.g. Command, Query, Repository...
- Single Responsibility Principle
- Split write and read
- Support sync and notification evens
- Flexibility & Extensibility
- Event Bus allow us plug in new module to handler new events
- Can be noSQL System
- Writing to a file server, QUEUE
- Testing
- Each class are single responsibility, we can easily write unit test with mock
.........................................
Any comments are welcome.