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.
// Command (write)
class CreateOrderCommand { orderId, customerId, items }
// Query (read)
class OrderSummaryView { orderId, total, status } // denormalizedCRUD — one model for read and write. CQRS — separation, more code, better for complex domains. For simple apps — overkill.
No. CQRS works with regular SQL too. But ES complements well — write side writes events, read side materialises views.
Async via events (Kafka, RabbitMQ). Eventual consistency — read model lags seconds to minutes.