Pattern 06 / DATA

CQRS (Command Query Responsibility Segregation)

Use this when read needs and write invariants fighting over the same model.

Pressure
Read needs and write invariants fighting over the same model
Mechanism
Separate command/write models from query/read models and synchronize them through events or projections
Toll
Two models, projection lag, and more moving pieces
Architecture plate06
Diagram for CQRS (Command Query Responsibility Segregation)
Executive brief

CQRS (Command Query Responsibility Segregation) fits when read needs and write invariants fighting over the same model. Mechanism: separate command/write models from query/read models and synchronize them through events or projections. Use it for systems with complex validation plus fast search, lists, or aggregates. The toll: two models, projection lag, and more moving pieces.

Use when

Systems with complex validation plus fast search, lists, or aggregates.

Example

Orders written relationally while catalog/search is served from elasticsearch.

Review framing

Describe the pressure first, then the mechanism, then the cost. That keeps the design grounded.

Same pressure family

Data Storage Patterns

01Primary-Replica (Leader-Follower)02Sharding (Horizontal Partitioning)03Consistent Hashing04Write-Ahead Log (WAL)05Event Sourcing
โ† 0507 โ†’