Skip to content

What is CQRS

Key idea:

CQRS (Command Query Responsibility Segregation) — a pattern where read and write operations use different data models, often different databases. Write-side handles commands (create/update), read-side — queries. Applied at high read-load (social feeds, analytics) or complex domains. Often paired with Event Sourcing. Complexity overhead high — unnecessary for CRUD apps.

Below: details, example, related terms, FAQ.

Details

  • Command model: strong consistency, validation, business rules
  • Query model: denormalized, optimized for specific read patterns
  • Sync between them — via events (eventual consistency)
  • Separate scaling: read side 10× replicas, write side stays small
  • Popular frameworks: MediatR (.NET), EventStore, Axon (Java)

Example

// Command (write)
class CreateOrderCommand { orderId, customerId, items }
// Query (read)
class OrderSummaryView { orderId, total, status }  // denormalized

Related Terms

Learn more

Frequently Asked Questions

CQRS vs simple CRUD?

CRUD — one model for read and write. CQRS — separation, more code, better for complex domains. For simple apps — overkill.

Is Event Sourcing mandatory?

No. CQRS works with regular SQL too. But ES complements well — write side writes events, read side materialises views.

How to sync the read model?

Async via events (Kafka, RabbitMQ). Eventual consistency — read model lags seconds to minutes.