What is CQRS
CQRS (Command Query Responsibility Segregation) is an architectural pattern that separates the read model and the write model of a system. Commands (writes) go to one model. Queries (reads) go to another.
How it works
The write model handles commands — validated, business-rule-enforced operations that change state. It is typically normalized and uses a relational database with ACID guarantees.
The read model handles queries — fast lookups optimized for how the data is displayed. It is often denormalized and may use a completely different database (Elasticsearch for search, Redis for key-value lookups).
The two models are connected through events. When the write model changes state, it emits an event. The read model consumes the event and updates its view.
Why it matters
Reads and writes have different performance characteristics. A single model forces compromises — the schema is either optimized for writes (normalized, slow joins for reads) or for reads (denormalized, complex updates). CQRS eliminates this tension.
The tradeoff is complexity: two models to maintain, an event pipeline between them, and eventual consistency where the read model temporarily lags behind the write model.
For the full explanation, see How CQRS Works.