← Lessons

quiz vs the machine

Gold1500

System Design

CQRS

Split the model that writes data from the model that reads it so each can be tuned on its own.

4 min read · core · beat Gold to climb

Two models, one system

CQRS stands for command query responsibility segregation. The idea is to use one model for changing data, the command side, and a separate model for reading it, the query side. Each side gets a shape tuned for its job.

In a traditional design the same model handles both, which forces compromises. Reads often want denormalized, fast lookups while writes want validated, normalized structure. CQRS lets them diverge.

How it flows

  • A command expresses intent to change state and is validated by the write model.
  • The write produces an update that is projected into one or more read models.
  • Queries hit the read models, which are shaped exactly for the screens that need them.

What you accept

The read side is often updated asynchronously, so it can be briefly behind the write side. This eventual consistency is fine for many features but must be considered in the user experience. CQRS adds moving parts, so reach for it when read and write needs genuinely diverge, not by default.

Key idea

CQRS separates write and read models so each can be optimized, at the cost of eventual consistency.

Check yourself

Answer to earn rating on the learn ladder.

1. What does CQRS separate?

2. What consistency trade off commonly comes with CQRS?