> Now, let us get back to my original question. What kinds of event we should
> use to rebuild the domain state? Currently, in my opinion, I guess that only
> the events which are created and produced by domain can be used to rebuild
> the domain state.
Correct
>The command (in CQRS architecture) probably should not be
> used to rebuild the domain state, right?
>
Correct and the order of LMAX itself is irrelevant ( and nor really an
important part of LMAX architecture) and i would not use it ( It is
just event processor getting market events and more importantly events
based on market depth scans and some dummy trades) , however the
KEY to LMAX is slow things ( IO !) like most GUIs and node.js are on
another thread , that way the command processing thread (s) stays
running has few/no locks , context switches and hence has a high L1
and L2 cache hit and does huge amounts of work . Messaging between
threads is done in a non locking manner via a ring buffer (
"disruptor").
re 2 sub commands . The real key is in a typical CQRS system you go
1.Command Processor
send command
handle command
bring AR/entity into memory
run logic
fire events
2.Event Processor
apply changes
save changes
handle errors
Which i would retain as it has many advantages . However handle
command normally has IO to bring in the information needed into memory
( eg create the relevant aggregate) and obviously save changes so
these cannot be done on the command processor thread ! The easiest way
is as i described in the last email.
Once you do the above ( pull out IO) then you have to handle errors
and failures in my case an exception is thrown and callers to the
command processor can hook these events ( which are fired on worker
thread so the caller can not interfere with the command processor ) .
Note on a parallel systems the IO is normally done on the same thread
( but the OS often will just block it and use io completion threads
behind the scenes) , it is difficult to say what is better on a high
performance system eg some of the factors
- Performance vs ease of coding
- Do you handcraft your parallel locking
- Do you use a lib to make parrallelism easy eg RX
- Do you have an existing CQRS framework which is mature for many threads
- Do you have a mature SOA environment
- Developer skills
- What DB solution do you use
LMAX on CQRS has a significant cost in terms of non standard
infrastructure ( eg call backs to create new commands ) but once
written its pretty easy to code for , eg probably < 10% overhead to a
standard CQRS system. Parallel optimized systems would require less
infrastructure code but be much more expensive to find and tune the
bottle necks.
I would also add CQRS systems have lower contention than traditional
systems so benefit less from LMAX but i think the highest performing
systems would be mostly LMAX with some hand crafted parallelism
.though such a system would need an incredible and custom event store.
If your still interested in LMAX CQRS send me a message and i will
mail you some code when im back in shanghai.
Ben