56 results available
Sign in
Skills directory

cqrs-implementation

wshobson

·

Last changed
Hardened

This skill has been hardened by Chainguard

Last changed

This version passed the hardening gate. Hardening applied 7 targeted changes and preserved all other text. Classified findings before hardening: 0. Classified findings closed: 0. Classified findings remaining: 0. Unclassified scanner findings remaining: 0. Review findings closed: 7. Review findings remaining: 2.


Open before hardening

None

Open after hardening

None


Expand
File
Group
Subtype
Severity
Status

No findings available

0 findings


SKILL.md

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

Command

Intent to change state

Command Handler

Validates and executes commands

Event

Record of state change

Query

Request for data

Query Handler

Retrieves data from read model

Projector

Updates 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. Treat those templates as reference examples, and review and adapt them before use.

Best Practices

Do's

  • Separate command and query models - Different needs
  • Use eventual consistency where the business tolerates lag - Define acceptable propagation delay
  • Validate in command handlers - Before state change
  • Authenticate and authorize every command - Check caller identity and permissions in the command handler before any state change
  • Denormalize read models - Optimize for queries
  • Bound query inputs - Cap page size and accept sort fields only from a fixed list
  • Version your events - For schema evolution
  • Make projectors idempotent and validate events - Track event IDs or sequence numbers to reject duplicates and replays, validate schema and version, and accept events only from the trusted event store
  • Hold the checkpoint at a failed event - Retry or stop until the failure is handled

Don'ts

  • Don't use the read model for command validation - Load state from the write model
  • Don't couple read/write schemas - Independent evolution
  • Don't make authorization or invariant decisions from read models - Enforce permissions, balances, and uniqueness against the write model in the command handler, with optimistic concurrency
  • Don't over-engineer - Start simple
  • Don't ignore consistency SLAs - Define acceptable lag

Install

Install with chainctl
chainctl skill install public/wshobson/cqrs-implementation:latest
Get started with chainctl
View source

Harden your own skills

Bring Chainguard's hardening pipeline to your first-party skills — custom rulesets, automated remediation, full audit trail.

Provenance

Upstream sourcehttps://github.com/wshobson/agents
Upstream commitbe57c0b2e3c05c528ca6132b87410b385718775f
OCI reference

skills.cgr.dev/public/github.com/wshobson/plugins/backend-development/skills/cqrs-implementation:latest

License

MIT

Files

HARDENING.md

LICENSE

SKILL.md

references/details.md


The trusted source for open source

Talk to an expert
PrivacyTerms

Product

Chainguard ContainersChainguard LibrariesChainguard VMsChainguard OS PackagesChainguard ActionsChainguard Agent SkillsIntegrationsPricing
© 2026 Chainguard, Inc. All Rights Reserved.
Chainguard® and the Chainguard logo are registered trademarks of Chainguard, Inc. in the United States and/or other countries.
The other respective trademarks mentioned on this page are owned by the respective companies and use of them does not imply any affiliation or endorsement.