What is CQRS (Command Query Responsibility Segregation)?
Turkish: CQRS
CQRS separates commands from queries so write models and read models can be designed, scaled, and secured for different needs.
What is CQRS?
CQRS (Command Query Responsibility Segregation) is an architectural pattern that treats data-changing operations and data-reading operations as separate models. Creating an order, reducing stock, or capturing a payment is a command; showing order details, reports, or lists is a query.
How Does It Work?
In a traditional CRUD model, the same data model is used for reads and writes. With CQRS, the write model focuses on business rules and consistency, while the read model produces fast, simple views for screens and reports. The read side is often denormalized and may use a cache or separate database.
Relationship with Event Sourcing and DDD
CQRS does not require event sourcing, but the two are often used together. Event sourcing stores changes as events on the write side, and read models can be rebuilt from those events. In DDD projects, complex domain rules can be modeled more clearly on the command side.
When Is It Useful?
- Read traffic is much higher than write traffic
- Reporting or search screens need a different shape than the transactional model
- Business rules are complex and the domain model must be protected
- Teams need to scale or secure read and write workloads differently
What to Watch
CQRS can add unnecessary complexity to simple CRUD applications. When the read model updates after the write model, eventual consistency appears; user-facing status, retries, and compensation behavior must be designed explicitly.
Related Terms
DDD models complex business domains through domain language, bounded contexts, and software structures aligned with real rules.
Event SourcingEvent sourcing stores application state as ordered, immutable records of changes rather than only keeping the latest value.
Saga PatternThe Saga pattern splits a distributed business transaction into steps and uses compensating actions to preserve consistency when a step fails.