NEW
Also known as: Command Query Responsibility Segregation
An architectural pattern that separates read and write models to optimize performance, scalability, and complexity management.
DESCRIPTION
CQRS uses different models for commands (writes) and queries (reads), enabling independent scaling and tailored data representations. It often pairs with event sourcing to capture changes as events. Read models can be denormalized and materialized for fast queries. The pattern supports complex domains where reads vastly outnumber writes. It introduces eventual consistency between models and added complexity in synchronization. Proper messaging, idempotency, and versioning are crucial.
ALTERNATIVE DEFINITIONS
Martin Fowler
The basic idea is that you use a different model to update information than the model you use to read information.
Highlights the core separation of read and write models.
Microsoft Learn
CQRS separates reads and writes into different models, using commands to update data and queries to read data.
Explicitly frames commands and queries as separate models.
Greg Young
At its heart, CQRS is the notion that you can split the conceptual model for reading from the model for writing.
Originator’s concise definition emphasizing conceptual split.
RELATED TERMS
Event Sourcing Domain-Driven Design Materialized View Read Model Write Model Microservices Eventual Consistency Queue Aggregate Command Handler
COMPETING TERMS
KNOWLEDGE AREAS
Software Modeling Data Architecture Software Engineering Real-time & Streaming Data
TARGET AUDIENCE
Software Developer Data Architect AI Product Manager Enterprise Architect Cloud Architect
EXTERNAL SOURCES
- Wikipedia - Command–query separation#Command Query Responsibility Segregation
- Microsoft - Official CQRS pattern guidance
- Martin Fowler - Thought leadership on CQRS
- Greg Young - Founder’s overview and resources
TOP QUESTIONS
Why use CQRS for high-read systems?
CQRS lets you optimize read models separately, enabling denormalization and caching for fast queries without harming write performance.
Category: Relevancy
Does CQRS require Event Sourcing?
No. They’re complementary; CQRS can be applied with traditional persistence or paired with event sourcing for auditability.
Category: Misunderstanding
What is the main trade-off of CQRS?
Added complexity and eventual consistency between models. Operational and testing overhead increases.
Category: Risks
How are read models updated in CQRS?
Write-side emits events; read-side handlers project events into materialized views or caches for fast queries.
Category: Design
When is CQRS overkill?
In simple CRUD applications or small teams, the overhead outweighs benefits. Start simple.
Category: Opinion
How does CQRS support scalability?
Read and write workloads scale independently. You can horizontally scale read replicas or caches without impacting writes.
Category: Performance
What data consistency does CQRS imply?
Typically eventual consistency across read models; strict consistency requires more coordination and latency.
Category: Concept
What’s a good first step to adopt CQRS?
Separate query services from write endpoints and introduce a materialized view for a high-value read use case.
Category: Getting Started
How to test CQRS systems effectively?
Test command-side invariants, event flows, and projection correctness. Use contract tests for read models.
Category: Testing