CQRS (Command Query Responsibility Segregation)

Scaling

Also known as: command query separation

CQRS is an architectural pattern that separates read operations (queries) from write operations (commands) into different models, allowing each to be optimized, scaled, and evolved independently.

In traditional CRUD architectures, the same data model handles both reads and writes. CQRS recognizes that read and write workloads often have very different requirements: writes need validation, business rules, and consistency; reads need fast, denormalized data in the shape the UI needs.

With CQRS, commands (writes) go through a model optimized for validation and business logic, while queries (reads) use a separate model optimized for fast retrieval — potentially a different database entirely (e.g., writes to PostgreSQL, reads from Elasticsearch).

CQRS is often combined with event sourcing: commands produce events, which are stored in an event log and projected into read-optimized views. This provides a complete audit trail and the ability to rebuild read models from the event history.

CQRS adds complexity and is not needed for simple CRUD applications. It shines in systems with high read/write ratio asymmetry, complex domain logic, multiple read representations, or event-sourcing requirements.

Related Terms

Ready to design?

Practice using cqrs (command query responsibility segregation) in a real system design on Supaboard's interactive whiteboard.

Browse Challenges