What is CQRS (Command Query Responsibility Segregation)?
Answer
CQRS separates the write model (Commands — which change state) from the read model (Queries — which return data). Instead of a single model serving both reads and writes, you have two: a command stack that processes state-changing operations and emits events, and one or more query stacks that maintain denormalized, read-optimized views of the data built from those events. This allows the read model to be independently scaled, independently structured (e.g., a materialized view in Redis or Elasticsearch optimized for specific queries), and independently deployed. CQRS is powerful but adds significant complexity — it is most beneficial in systems with high read/write asymmetry or where reads need very different data shapes than writes produce.
More Microservices Architecture Questions
View all →- Intermediate What is event-driven architecture and how does it apply to microservices?
- Intermediate What is the Saga pattern in microservices?
- Intermediate What is event sourcing in microservices?
- Intermediate What is the Circuit Breaker pattern?
- Intermediate What is the Bulkhead pattern in microservices?