System Design
9. Message Queues and Event-Driven Systems11. Microservices ArchitectureAnimated
CQRS
Separate models for reading and writing.
The idea
Commands change state on one model; queries read from another optimised model.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
- client
- gateway / proxy
- service
- cache
- data store
- queue / stream
Writes (commands) and reads (queries) use separate models.
- step:
- 1/4
- at:
- Client
1/12
The green dot is a request moving through the system.
Step by step
- 1Commands go to the write model
- 2Events update the read model
- 3Queries use the read model
- 4Models scale separately
Where it is used
Read-heavy complex domains.
Watch out for
Read model lag and extra complexity.