CQRS
Command/query separation, read/write model separation, eventual consistency, and materialized views.
Overview
Overview CQRS separates the model for reading data from the model for writing data. Instead of a single data model that handles both reads and writes (the traditional CRUD approach), CQRS uses distinct models optimized for their specific purpose: a write model that enforces business rules and an read model that is shaped for fast, efficient queries.
The motivation is that read and write workloads have fundamentally different characteristics. Writes need validation, business rules, and transactions. Reads need speed, denormalization, and flexibility. A single model that tries to serve both compromises on each. CQRS eliminates this tension by letting each side be independently optimized and scaled.
When combined with event sourcing, CQRS becomes especially powerful: the write side appends events, and the read side builds materialized views by projecting those events into query-optimized shapes. This pairing is used at companies like Axon (banking), EventStore (infrastructure), and many financial systems. In interviews, be ready to discuss when CQRS is worth the added complexity and when a simpler CRUD model suffices.
Key concepts
- Command vs Query separation
- Write model (command side)
- Read model (query side, materialized views)
- Eventual consistency between read and write
- Projection and denormalization
- Event sourcing + CQRS synergy
- Consistency trade-offs and sync strategies
Interview questions
- How does CQRS separate reads and writes, and what are the architectural options?
- How do you handle eventual consistency between the write and read models?
- When should you use CQRS and when is it overkill?
- How do you build and maintain projections (read models) in a CQRS system?
Sign up free to read the full topic
More Microservices topics
Start free on Cariara · Coding problems · System design studio