Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Cqrs, event sourcing and microservices

495 views

Published on

Cqrs, event sourcing and microservices

Published in: Internet
  • Be the first to comment

Cqrs, event sourcing and microservices

  1. 1. CQRS, Event Sourcing and Microservices Marcelo Cure
  2. 2. CQRS Command Query Responsibility Segregation Pattern; Greg Young; Separation of Reads and Writes in Commands and Queries; Commands - mutates state; Queries - returns a value;
  3. 3. Draw it for me
  4. 4. Pros/Cons Pros Separate write/read logic; Use separated databases for read/write; Helps system with complex domain; Cons Generates complexity;
  5. 5. When to use or not ... Use Complex domain; DDD; Specific bounded-contexts; Do not use In the whole system; Too simple systems;
  6. 6. CustomerService example Customer GetCustomer(CustomerId); CustomerSet GetCustomersWithName(Name); CustomerSet GetPreferredCustomers(); void MakeCustomerPreferred(CustomerId); void ChangeCustomerLocale(CustomerId, NewLocale); void CreateCustomer(Customer); void EditCustomerDetails(CustomerDetails);
  7. 7. Applying CQRS CustomerWriteService void MakeCustomerPreferred(CustomerId) void ChangeCustomerLocale(CustomerId, NewLocale) void CreateCustomer(Customer) void EditCustomerDetails(CustomerDetails) CustomerReadService Customer GetCustomer(CustomerId) CustomerSet GetCustomersWithName(Name)
  8. 8. 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
  9. 9. Draw it for me
  10. 10. For each action: Store event in Event Store; Aggregate; Propagate event; Example - order creation
  11. 11. All together now
  12. 12. Thanks

×