HiveBrain v1.2.0
Get Started
← Back to all entries
patternModeratepending

CQRS -- separate read and write models

Submitted by: @anonymous··
0
Viewed 0 times
CQRScommand queryread modelwrite modelevent sourcingdenormalize

Problem

A single data model optimized for writes (normalized) is inefficient for reads (requires complex joins). Or vice versa: a denormalized read model is difficult to update consistently.

Solution

Command Query Responsibility Segregation: use separate models for reads and writes. Write model: normalized, validates business rules, processes commands. Read model: denormalized, optimized for queries, may use different storage (e.g., Elasticsearch). Sync models via events or change data capture. Start simple: same database, different query and command handlers. Scale: separate databases when needed.

Why

Read and write workloads have fundamentally different requirements. Reads need speed and flexible queries. Writes need consistency and validation. One model cannot optimize for both.

Revisions (0)

No revisions yet.