CRQS and Event Sourcing

CQS

command query separation

a method should only have been responsible for executing a command

against an object or it should be responsible for retrieving information from real objects query

you should never do both.

CQRS

command query responsibility separation or segregation

you should have a separate object for your commands

and a separate object for your queries

 COMMANDS <- CLIENT <------------
    |                           |
    V                           |
DISPATCHER                      |
    |                           |
    V                         VIEW
 HANDLER                        ^
    |                           |
    V                         READ
  DOMAIN                    DATABASE
    |                           ^
    V                           |
REPOSITORY                  PROJECTION  
    |                           ^
    V                           |
  EVENTS  -> EVENT STORE -> PROJECTION
                             MANAGER
```
ADMIN PATIENT (Command)
      |
      V

———-DISPATCHER————-
| | |
| | |
V V V
ADMIT TRANSFER DISCHARGE
HANDLER HANDLER HANDLER



ADMIN HANDLER
|
V ——————————————
ENCOUNTER |AGGREGATE |
^ |Events + 1 |—————————————|
|Events| |LIST VERSION APPLY |
| V ——————————————
REPOSITORY



 PATIENT
 ADMITTED
    |
    V
PROJECTION  <----- CHECKPOINT
 MANAGER    ----->
    |
    V
 WARD VIEW
PROJECTION
    |
    V
 WARD VIEW

```

EVENTUAL CONSISTENCY

Things need to do

  1. Validing command is correct.

https://www.youtube.com/watch?v=8JKjvY4etTY
https://www.youtube.com/watch?v=holjbuSbv3k