Command Query Responsibility Segregation — separate write models (commands, invariants) from read models (projections, denormalized views), synchronization via events, eventual consistency handling in UI and APIs, when not to use it. Use when read and write needs diverge strongly (CQRS, read model, projection, command handler, eventual consistency).
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Cqrs?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/vectora-os-cqrs)
---
name: cqrs
description: Command Query Responsibility Segregation — separate write models (commands, invariants) from read models (projections, denormalized views), synchronization via events, eventual consistency handling in UI and APIs, when not to use it. Use when read and write needs diverge strongly (CQRS, read model, projection, command handler, eventual consistency).
metadata:
category: design-patterns
---
# CQRS
## Purpose
Optimize writes for correctness and reads for query needs independently.
**Use when:** read patterns differ greatly from write structure, or read load dominates.
**Not for:** simple CRUD — CQRS adds moving parts.
## Inputs
- Command and query requirements, consistency needs.
## Outputs
- Command model, read model designs, sync mechanism, consistency strategy.
## Read first
- [Project Brain](../../../project-brain/README.md) — `npm run brain -- query "cqrs"` for prior decisions, patterns and anti-patterns.
## Steps
1. **Justify.** Show why one model fails (query complexity, load); else stop.
Done when the need is evidenced.
2. **Commands.** Design command handlers enforcing invariants on the write model.
Done when each command validates and emits events.
3. **Projections.** Design read models per query; update from events idempotently.
Done when projections can be rebuilt.
4. **Consistency.** Decide UX for lag (read-your-writes, version tokens, optimistic UI).
Done when lag is handled visibly.
## Best practices
- Make projections rebuildable from source.
- Idempotent projection handlers with checkpoints.
- Start with same database, separate models.
## Common mistakes
- Applying CQRS system-wide.
- Ignoring read-after-write expectations.
- Non-idempotent projections.
## Example
Order dashboard read model denormalizes customer and totals; updated from `OrderPlaced`/`OrderShipped`; UI shows "updating…" using a version token.
## Reusable prompt
```text
Apply the CQRS skill (.agents/skills/cqrs/SKILL.md).
Context: {{task card or question; links to PRD, ADRs, code paths}}
Constraints: {{approved thresholds, deadlines, allowed files}}
Decide whether CQRS is justified; if yes, design commands, projections, sync and the consistency strategy.
Return: Command model, read model designs, sync mechanism, consistency strategy..
Cite evidence (file:line, command output, source) for every claim; list open questions separately.
```