cqrs, event sourcing and microservices

12
CQRS, Event Sourcing and Microservices Marcelo Cure

Upload: marcelo-cure

Post on 09-Feb-2017

209 views

Category:

Internet


4 download

TRANSCRIPT

Page 1: Cqrs, event sourcing and microservices

CQRS, Event Sourcing and Microservices

Marcelo Cure

Marcelo Cure
do we really need it?
Page 2: Cqrs, event sourcing and microservices

CQRSCommand Query Responsibility Segregation

Pattern;

Greg Young;

Separation of Reads and Writes in Commands and Queries;

Commands - mutates state;

Queries - returns a value;

Page 3: Cqrs, event sourcing and microservices

Draw it for me

Page 4: Cqrs, event sourcing and microservices

Pros/ConsPros

Separate write/read logic;

Use separated databases for read/write;

Helps system with complex domain;

Cons

Generates complexity;

Page 5: Cqrs, event sourcing and microservices

When to use or not ...Use

Complex domain;

DDD;

Specific bounded-contexts;

Do not use

In the whole system;

Too simple systems;

Page 6: Cqrs, event sourcing and microservices

CustomerService exampleCustomer GetCustomer(CustomerId);

CustomerSet GetCustomersWithName(Name);

CustomerSet GetPreferredCustomers();

void MakeCustomerPreferred(CustomerId);

void ChangeCustomerLocale(CustomerId, NewLocale);

void CreateCustomer(Customer);

void EditCustomerDetails(CustomerDetails);

Page 7: Cqrs, event sourcing and microservices

Applying CQRSCustomerWriteService

void MakeCustomerPreferred(CustomerId)

void ChangeCustomerLocale(CustomerId, NewLocale)

void CreateCustomer(Customer)

void EditCustomerDetails(CustomerDetails)

CustomerReadService

Customer GetCustomer(CustomerId)

CustomerSet GetCustomersWithName(Name)

CustomerSet GetPreferredCustomers()

Page 8: Cqrs, event sourcing and microservices

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

Page 9: Cqrs, event sourcing and microservices

Draw it for me

Page 10: Cqrs, event sourcing and microservices

For each action:

Store event in Event Store;

Aggregate;

Propagate event;

Example - order creation

Page 11: Cqrs, event sourcing and microservices

Alltogethernow

Page 12: Cqrs, event sourcing and microservices

Thanks