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.