advanced

CQRS

Separate command and query models when read shape, scale, or latency needs differ enough to justify synchronization complexity.

Command Query Responsibility Segregation splits write models optimized for business rules from read models optimized for queries — different schemas, stores, or scaling. Updates propagate via events or sync pipelines; temporary lag between write and read is expected.

Trade-off: read performance and tailored views versus synchronization complexity and stale reads.

On interviews: when CQRS is overkill for a CRUD service; design a read model for a search page fed by order events.

Common pitfalls: CQRS everywhere without read pain; no strategy for read model rebuild; dual writes without outbox.

Checklist:

  • Justify separate read store with concrete query needs.
  • Project read models idempotently from events.
  • Plan full rebuild from event log.
  • Document staleness for each read endpoint.