Skip to content
BENIBIX Learn

Command Query Responsibility Segregation (CQRS)

Development🏗️ ArchitectureEvents and Messages

Also known as CQRS, Command Query Separation

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

Think of it like

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

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.

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.

Common mistake

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

Key takeaways

  1. 1
    Commands change. Queries only read.
  2. 2
    Separate models. Each fit for its job.
  3. 3
    Only when needed. It adds parts.

Compare