SOLID & Design Patterns Interview Question #63
What is the CQRS pattern?
Advanced Patterns, CQRS & Domain-Driven Design Fundamentals Mid-Level Intermediate
Quick Interview Answer
Command Query Responsibility Segregation separates operations that change state from operations that read state. Commands represent requested changes, while queries retrieve data without changing business state.
Detailed Explanation
Command Query Responsibility Segregation separates operations that change state from operations that read state. Commands represent requested changes, while queries retrieve data without changing business state.
CQRS can range from simple separation of request models and handlers to architectures with different read and write data models. Separate databases are not required. The added complexity should be justified by domain or scalability needs.
Code Example
public record CreateOrderCommand(
int CustomerId);
public record GetOrderQuery(
int OrderId);
public class CreateOrderHandler { }
public class GetOrderHandler { }