Cqrs, event sourcing and microservices
-
Upload
marcelo-cure -
Category
Internet
-
view
195 -
download
4
Transcript of Cqrs, event sourcing and microservices
CQRS, Event Sourcing and Microservices
Marcelo Cure
CQRSCommand Query Responsibility Segregation
Pattern;
Greg Young;
Separation of Reads and Writes in Commands and Queries;
Commands - mutates state;
Queries - returns a value;
Draw it for me
Pros/ConsPros
Separate write/read logic;
Use separated databases for read/write;
Helps system with complex domain;
Cons
Generates complexity;
When to use or not ...Use
Complex domain;
DDD;
Specific bounded-contexts;
Do not use
In the whole system;
Too simple systems;
CustomerService exampleCustomer GetCustomer(CustomerId);
CustomerSet GetCustomersWithName(Name);
CustomerSet GetPreferredCustomers();
void MakeCustomerPreferred(CustomerId);
void ChangeCustomerLocale(CustomerId, NewLocale);
void CreateCustomer(Customer);
void EditCustomerDetails(CustomerDetails);
Applying CQRSCustomerWriteService
void MakeCustomerPreferred(CustomerId)
void ChangeCustomerLocale(CustomerId, NewLocale)
void CreateCustomer(Customer)
void EditCustomerDetails(CustomerDetails)
CustomerReadService
Customer GetCustomer(CustomerId)
CustomerSet GetCustomersWithName(Name)
CustomerSet GetPreferredCustomers()
Each application state change is a new event;
Sequence of events;
Reconstruct past states with event log (replay);
Events can generate other events;
Event Sourcing
Draw it for me
For each action:
Store event in Event Store;
Aggregate;
Propagate event;
Example - order creation
Alltogethernow
Thanks