Skip to content

CONCEPT Cited by 1 source

CQRS (Command-Query Responsibility Segregation)

CQRS — Command-Query Responsibility Segregation — is the idea that the data model optimized for accepting writes (commands) doesn't have to be the same data model serving reads (queries). The write model is typically normalized, strongly consistent, and optimized for focused updates; the read model is typically denormalized, pre-computed, and optimized for the queries the application actually runs. A pipeline (often async) projects writes from the command model into one or more query models.

Why the split matters

Many systems meet a tension where one data shape is hostile to the other:

  • Operations-friendly shape (normalized relational with lots of entities + joins) is great for small edits, audit, constraints, but expensive to read in bulk.
  • Read-friendly shape (denormalized, pre-joined, indexed by the query dimension — e.g., a pre-built graph, a materialized aggregate, a wide search doc) is fast to serve but awkward to edit in-place.

CQRS lets both exist and keeps each optimized for its job. The read model is a derived artifact — losing it is tolerable because it can be rebuilt from the write model (the source of truth).

Shapes seen in the wild

  • Async-projected read model — writes go to the command store; a pipeline reacts and rebuilds / updates the read store. Read store can be a different technology entirely. (Canva print routing: relational DB → async rebuild → Redis graph; see patterns/async-projected-read-model.)
  • OLTP + OLAP — the warehouse as a derived read model for analytical queries. Canva's billing counting pipeline does this too (DynamoDB → Snowflake → RDS for serving). See concepts/oltp-vs-olap, concepts/elt-vs-etl.
  • Materialized views — the RDBMS version of the same idea, kept in-engine.

Consistency model

The projection is usually eventually consistent — there's a lag between write and read-model update. Some systems bound this with versioned reads, others accept it and advertise freshness. CQRS doesn't require strong consistency, but it doesn't forbid it either; the read model can block on the projection if the application can afford the latency cost.

Seen in

Last updated · 200 distilled / 1,178 read