2. Apresentação
Tech Lead at MovilePay
João Rafael Campos
joao.campos@movile.com
/jrafaelcam
/rafaelcam
@rafaelcam
Senior Software Engineer at MovilePay
Diego Brener
diego.brener@movile.com
/diegobrener
/diegosilva13
@dbsilva
6. Day 2 Problems
➔Different reading and writing needs
➔Very large business classes
➔Complex queries
➔Queries between services (Microservices)
➔Lack of traceability of operations
9. CQRS
➔Command Query Responsibility Segregation
➔It is a fancy name for an architecture that uses different data models to
represent read and write operations
10. TWO MODELS
Command Model
➔Focused on executing tasks
➔Only contains data necessary for task
execution and decision making
Query Model / Projections
➔Focused on delivering information.
11. Synchronization of Models
➔Changes in the Command Model should be visible in the Query Model.
◆ Shared data source
◆ Stored procedures
◆ Event Driven Architecture
12. CQRS is not...
➔Event sourcing
➔Eventual consistency
➔It is not noSql and/or 2 databases
14. DDD Concepts
➔Aggregates (A group of associated objects which are considered as one unit
with regard to data changes)
➔Emphasis on the design of a model
➔Use of ubiquitous language
15. What is Event Sourcing?
Martin Fowler
➔Event Sourcing ensures that all changes to application
state are stored as a sequence of events
➔Not just can we query these events, we can also use the
event log to reconstruct past states
➔Construct different current states
"We can query an application's state to find out the current state of the world,
and this answers many questions. However there are times when we don't just
want to see where we are, we also want to know how we got there"
19. Event Sourcing
➔Send the command
➔Process the command
➔If the command is valid, the event will be sent
If the command is not valid, an error is returned
➔Event is stored in the Event Store and sent to the Event
Bus
➔Event is consumed by a handler and the status of the
view is changed
20. Additional Benefits
Easy eventual business consistency
> Corrective events
Robust to data corruption
(bugs, manual changes..)
> Rebuild state ignoring wrong events
25. Axon Framework
➔Provides a clean, elegant Java API for writing DDD, CQRS
and Event Sourcing applications
➔Open Source
➔It provides basic building blocks for writing aggregates,
commands
➔Integrates with Spring Boot and other frameworks
➔Focus on business logic
27. Command Handler
➔Accepts incoming commands
➔Interacts with the current state of the aggregate and
publishes events
➔Command model only contains data necessary for task
execution and decision making