|
| 1 | += CQRS (Command Query Responsibility Segregation) |
| 2 | +:categories: software-architecture |
| 3 | +:roles: software-architect, software-developer |
| 4 | +:proponents: Greg Young, Bertrand Meyer, Udi Dahan |
| 5 | +:related: domain-driven-design, hexagonal-architecture, fowler-patterns |
| 6 | +:tags: cqrs, cqs, architecture, commands, queries, read-write-separation |
| 7 | + |
| 8 | +[%collapsible] |
| 9 | +==== |
| 10 | +Also known as:: CQS at architectural scale |
| 11 | + |
| 12 | +[discrete] |
| 13 | +== *Core Concepts*: |
| 14 | + |
| 15 | +Command Query Separation (CQS):: Bertrand Meyer's principle — methods either change state (commands) or return data (queries), never both |
| 16 | + |
| 17 | +Commands:: Write operations that change state and return void; represent intent as immutable command objects |
| 18 | + |
| 19 | +Queries:: Read operations that return data with no side effects; safe to retry and cache |
| 20 | + |
| 21 | +Separate read/write models:: Independent data models optimized for their respective purpose |
| 22 | + |
| 23 | +Eventual consistency:: Read model may lag behind write model; acceptable trade-off for scalability |
| 24 | + |
| 25 | +Event-based synchronization:: Domain events propagate changes from write side to read side projections |
| 26 | + |
| 27 | +Independent scalability:: Read and write sides can be scaled, deployed, and optimized independently |
| 28 | + |
| 29 | +Event sourcing optional:: CQRS does not require event sourcing; the patterns are complementary but independent |
| 30 | + |
| 31 | + |
| 32 | +Key Proponents:: Greg Young (coined CQRS), Bertrand Meyer (CQS origin, "Object-Oriented Software Construction", 1988), Udi Dahan |
| 33 | + |
| 34 | +[discrete] |
| 35 | +== *When to Use*: |
| 36 | + |
| 37 | +* Systems with asymmetric read/write workloads |
| 38 | +* Complex domains where read and write models diverge significantly |
| 39 | +* Event-sourced systems requiring materialized views |
| 40 | +* High-performance systems needing independent scaling of reads and writes |
| 41 | +* Collaborative domains with task-based UIs |
| 42 | + |
| 43 | +[discrete] |
| 44 | +== *Related Anchors*: |
| 45 | + |
| 46 | +* <<domain-driven-design,Domain-Driven Design>> - Often combined with CQRS for complex domains |
| 47 | +* <<hexagonal-architecture,Hexagonal Architecture>> - Ports and adapters complement CQRS separation |
| 48 | +* <<fowler-patterns,Fowler Patterns>> - CQRS builds on enterprise application patterns |
| 49 | +==== |
0 commit comments