# Command Query Responsibility Segregation (CQRS)

> Splitting the code that changes data from the code that reads it.

**Field:** Software Development  
**Category:** Architecture  
**Also known as:** CQRS, Command Query Separation

## Think of it like

Think of it like a library with two desks. One takes books back, and one helps you find them.

## Definition

CQRS splits the code that changes data from the code that reads it. Commands change things, like place order. Queries only read, like show my orders. Each side can have its own model, and often its own database, shaped for its job. Reads can then be fast and simple even when writes have many rules.

## Example

Emma's shop saves orders in a strict database that checks each rule. A second, simpler copy feeds the order history page. That page loads in a blink.

## Why it matters

Reads and writes often have very different needs. Splitting them lets each be shaped and scaled on its own.

## Common mistake

Using two databases for a simple app. Most apps do fine with one model for both until reads become a real problem.

## Three principles

- **Commands change.** Queries only read.
- **Separate models.** Each fit for its job.
- **Only when needed.** It adds parts.

## Related terms

- [Event Sourcing](https://learn.benibix.com/term/development/event-sourcing)
- [Database](https://learn.benibix.com/term/development/database)
- [Database Query](https://learn.benibix.com/term/development/query)
- [Software Architecture](https://learn.benibix.com/term/development/software-architecture)

## Told apart from

- [Event Sourcing vs CQRS](https://learn.benibix.com/compare/event-sourcing-vs-cqrs): Event sourcing and CQRS are often used together, so people mix them up, but they solve two different problems. Event sourcing is about how data is stored. Every change is kept as an event. CQRS is about how code is split. One side changes data, and another side reads it. Either one works fine without the other.

---

Source: https://learn.benibix.com/term/development/cqrs
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
