PluginBench
Skill
Pass
Audit score 90

cqrs-implementation

wshobson/agents

Implement CQRS to separate read and write models for scalable, high-performance architectures.

What is cqrs-implementation?

CQRS (Command Query Responsibility Segregation) separates command (write) and query (read) operations into independent models and handlers. Use it when you need to scale reads independently, optimize query performance, build event-sourced systems, or maintain different schemas for reads and writes.

  • Separate command and query APIs for independent scaling
  • Implement command handlers that validate and execute state changes
  • Create query handlers that retrieve data from optimized read models
  • Use event projectors to synchronize read models from write events
  • Support eventual consistency between read and write models
  • Enable denormalized read models optimized for specific query patterns

How to install cqrs-implementation

npx skills add https://github.com/wshobson/agents --skill cqrs-implementation
Claude Code
Cursor
Windsurf
Cline

How to use cqrs-implementation

  1. 1.Define your commands representing state-change intents
  2. 2.Implement command handlers that validate and execute commands, emitting events
  3. 3.Define your events as immutable records of state changes
  4. 4.Create query handlers that retrieve data from the read model
  5. 5.Implement projectors that listen to events and update the read model
  6. 6.Separate your command API endpoints from query API endpoints
  7. 7.Configure eventual consistency SLAs acceptable for your use case

Use cases

Good for
  • High-traffic applications where read and write loads differ significantly
  • Event-sourced systems that need to replay state from events
  • Complex reporting scenarios requiring denormalized data structures
  • Microservices architectures with independent read/write scaling needs
  • Systems requiring different data schemas for reads versus writes
Who it's for
  • Backend architects designing scalable systems
  • Full-stack developers building event-sourced applications
  • Teams managing high-traffic read-heavy or write-heavy workloads
  • Microservices teams needing independent service scaling
  • Database optimization specialists

cqrs-implementation FAQ

When should I use CQRS instead of a traditional CRUD model?

Use CQRS when you have different read and write performance requirements, need to scale reads independently, are building event-sourced systems, or require different data models for reads versus writes. For simple applications with uniform read/write patterns, traditional CRUD is simpler.

How do I handle the delay between writes and read model updates?

CQRS uses eventual consistency, meaning read models update asynchronously after events are processed. Define acceptable consistency SLAs for your application and communicate this delay to users where necessary.

Can I query data in command handlers?

No. Command handlers should only validate and execute writes. Queries should only read from the read model. This separation is fundamental to CQRS and prevents coupling between read and write concerns.

How do I evolve my event schema over time?

Version your events and implement event upcasters that transform old event formats to new ones. This allows you to change schemas without breaking event replay and historical data processing.

Do I need event sourcing to use CQRS?

No. CQRS and event sourcing are separate patterns. You can use CQRS with traditional databases by having command handlers update the write model and projectors denormalize data into the read model.

Full instructions (SKILL.md)

Source of truth, from wshobson/agents.


name: cqrs-implementation description: Implement Command Query Responsibility Segregation for scalable architectures. Use when separating read and write models, optimizing query performance, or building event-sourced systems.

CQRS Implementation

Comprehensive guide to implementing CQRS (Command Query Responsibility Segregation) patterns.

When to Use This Skill

  • Separating read and write concerns
  • Scaling reads independently from writes
  • Building event-sourced systems
  • Optimizing complex query scenarios
  • Different read/write data models needed
  • High-performance reporting requirements

Core Concepts

1. CQRS Architecture

                    ┌─────────────┐
                    │   Client    │
                    └──────┬──────┘
                           │
              ┌────────────┴────────────┐
              │                         │
              ▼                         ▼
       ┌─────────────┐          ┌─────────────┐
       │  Commands   │          │   Queries   │
       │    API      │          │    API      │
       └──────┬──────┘          └──────┬──────┘
              │                         │
              ▼                         ▼
       ┌─────────────┐          ┌─────────────┐
       │  Command    │          │   Query     │
       │  Handlers   │          │  Handlers   │
       └──────┬──────┘          └──────┬──────┘
              │                         │
              ▼                         ▼
       ┌─────────────┐          ┌─────────────┐
       │   Write     │─────────►│    Read     │
       │   Model     │  Events  │   Model     │
       └─────────────┘          └─────────────┘

2. Key Components

ComponentResponsibility
CommandIntent to change state
Command HandlerValidates and executes commands
EventRecord of state change
QueryRequest for data
Query HandlerRetrieves data from read model
ProjectorUpdates read model from events

Templates and detailed worked examples

Full template library and detailed worked examples live in references/details.md. Read that file when you need the concrete templates.

Best Practices

Do's

  • Separate command and query models - Different needs
  • Use eventual consistency - Accept propagation delay
  • Validate in command handlers - Before state change
  • Denormalize read models - Optimize for queries
  • Version your events - For schema evolution

Don'ts

  • Don't query in commands - Use only for writes
  • Don't couple read/write schemas - Independent evolution
  • Don't over-engineer - Start simple
  • Don't ignore consistency SLAs - Define acceptable lag