About Me
Felipe Fernández
About the talk
- 1. Objectives
- 2. CQS
- 3. CQRS
- 4. Event Sourcing
- 5. Related Concepts
- 6. Conclusion
Objectives
- Single Responsability Principle
- Scalability
- Model complex domains
CQS
- Command-query separation. Created by Bertrand Meyer
- Rethinking CRUD/REST
- Rethinking Mock/Stub
- Achieving better SRP at method level
CQRS
- Levels of split
- No split : PostsRepository
- Split at class level : PostsReader and PostsPersister
- Split at datastore level : Writes in RDBMS and Reads in NoSQL
- Split at deployable level : Write, read and materializer services.
EVENT SOURCING
- Append instead of update/delete in the write side
- Command vs Event
- CreatePost vs PostCreated
EVENT SOURCING BENEFITS
- Easy to create new views from scratch
- Audit
- Debugabble
- Disaster Recovery
- Unified log, same original datastore for OLAP and OLTP
RELATED CONCEPTS
- Aggregates
- Microservices
- Devops
- Event Storming
Aggregates
- Transactional Boundary
- Materialised from event store or write side store
- Command handler checks invariants of aggregates
- Example: Total value of unpaid orders for a customer must not exceed that customer's credit limit
- Customer credit and orders should be part of the same aggregate
- Application or datastore locks. Race conditions
Microservices
- Write, read and materialiser deployables
- Different scalability needs
- HTTP, Message queues... Different intercommunication protocols
- Lose type safety accross services
Devops
- Infra/ops gets more complicated
- Spinning up a local environment is harder
- Smoke tests are harder too
- Devs and ops need to collaborate more in this context
Conclusion
- Most sofisticated solution has a steep learning curve
- It scales really well
- Bring ubiquituous language to your system seamlessly
- Super fun, but harder
CQRS and Event Sourcing for dummies
Created by Felipe Fernández / @felipefzdz