cqrs-implementation

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

31,392 stars
Complexity: easy

About this skill

This skill provides a comprehensive guide to implementing Command Query Responsibility Segregation (CQRS) patterns. It's designed to assist with architecting scalable systems by clearly separating read and write concerns. Users can leverage this skill when optimizing query performance, building event-sourced systems, or when distinct data models are required for reading and writing operations. The skill offers detailed insights into how to apply CQRS effectively, enhancing an agent's ability to provide architectural guidance.

Best use case

Design and implement Command Query Responsibility Segregation (CQRS) patterns in software architectures for improved scalability, performance, and maintainability. This includes separating read and write models, optimizing query performance, building event-sourced systems, and handling complex reporting needs.

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

Users can expect to receive detailed guidance, best practices, and a conceptual understanding necessary to design and implement CQRS patterns effectively in their software architectures. The agent will help articulate the benefits and trade-offs of CQRS, suggest appropriate scenarios for its application, and provide structural advice for implementation, potentially including insights into integrating event sourcing.

Practical example

Example input

I'm designing a new microservice that needs to handle a high volume of reads and writes, and I'm considering CQRS. Can you explain the core concepts and guide me on how to approach its implementation, especially if I want to integrate event sourcing?

Example output

Certainly! CQRS (Command Query Responsibility Segregation) is an architectural pattern that separates operations that update data (commands) from operations that read data (queries). This allows for independent scaling and optimization. 

**Core Concepts:**
1.  **Commands:** Objects that represent an intent to change the system's state (e.g., `PlaceOrderCommand`). They are typically processed by a write model.
2.  **Queries:** Objects that represent a request for data (e.g., `GetProductDetailsQuery`). They are processed by a read model.
3.  **Write Model (Command Side):** Handles commands, performs business logic, and persists state changes, often using a transactional database. When integrated with event sourcing, this model emits events after state changes.
4.  **Read Model (Query Side):** Handles queries, often optimized for specific query patterns and denormalized data. It can be populated by listening to events from the write model or by direct projections.

**Implementation Approach with Event Sourcing:**
1.  **Define Commands & Domain Aggregates:** Identify the core business operations and the aggregates that encapsulate state and business rules.
2.  **Event Store:** Implement an event store to persist all state changes as a sequence of immutable events. This is your single source of truth for the write model.
3.  **Command Handlers:** Create handlers responsible for receiving commands, loading aggregates from the event store, executing business logic, and persisting new events.
4.  **Event Publishers/Subscribers:** Design a mechanism (e.g., message broker) to publish events from the write model and allow read models to subscribe.
5.  **Read Model Projections:** Create 'projectors' or 'denormalizers' that consume events and build optimized read models (e.g., SQL tables, NoSQL documents, search indices) tailored for specific queries.
6.  **Query Handlers:** Implement handlers for queries that retrieve data directly from the optimized read models.

**Benefits for your scenario:**
*   **Independent Scaling:** You can scale your read infrastructure (e.g., multiple read replicas, caches) separately from your write infrastructure.
*   **Optimized Performance:** Read models can be denormalized for fast queries, while the write model ensures transactional consistency.
*   **Flexibility:** Different data storage technologies can be used for read and write models.

Would you like to dive deeper into defining commands, setting up an event store, or perhaps an example of a read model projection?

When to use this skill

  • Separating read and write concerns in your application.
  • Scaling reads independently from writes to handle high traffic.
  • Building event-sourced systems where state changes are stored as a sequence of events.
  • Optimizing performance for complex query scenarios that might be slow on a write model.

When not to use this skill

  • The domain is simple, and standard CRUD (Create, Read, Update, Delete) operations are sufficient.
  • Your team or infrastructure cannot effectively operate and maintain separate read and write models.
  • The added complexity of CQRS outweighs its potential benefits for your specific project.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/cqrs-implementation/SKILL.md --create-dirs "https://raw.githubusercontent.com/sickn33/antigravity-awesome-skills/main/plugins/antigravity-awesome-skills-claude/skills/cqrs-implementation/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/cqrs-implementation/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How cqrs-implementation Compares

Feature / Agentcqrs-implementationStandard Approach
Platform SupportClaudeLimited / Varies
Context Awareness High Baseline
Installation ComplexityeasyN/A

Frequently Asked Questions

What does this skill do?

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

Which AI agents support this skill?

This skill is designed for Claude.

How difficult is it to install?

The installation complexity is rated as easy. You can find the installation instructions above.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# CQRS Implementation

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

## Use this skill when

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

## Do not use this skill when

- The domain is simple and CRUD is sufficient
- You cannot operate separate read/write models
- Strong immediate consistency is required everywhere

## Instructions

- Identify read/write workloads and consistency needs.
- Define command and query models with clear boundaries.
- Implement read model projections and synchronization.
- Validate performance, recovery, and failure modes.
- If detailed patterns are required, open `resources/implementation-playbook.md`.

## Resources

- `resources/implementation-playbook.md` for detailed CQRS patterns and templates.

Related Skills

event-store-design

31392
from sickn33/antigravity-awesome-skills

Design and implement event stores for event-sourced systems. Use when building event sourcing infrastructure, choosing event store technologies, or implementing event persistence patterns.

Software ArchitectureClaude

ddd-strategic-design

31392
from sickn33/antigravity-awesome-skills

Design DDD strategic artifacts including subdomains, bounded contexts, and ubiquitous language for complex business domains.

Software ArchitectureClaude

c4-container

31392
from sickn33/antigravity-awesome-skills

Expert C4 Container-level documentation specialist.

Software ArchitectureClaude

c4-component

31392
from sickn33/antigravity-awesome-skills

Expert C4 Component-level documentation specialist. Synthesizes C4 Code-level documentation into Component-level architecture, defining component boundaries, interfaces, and relationships.

Software ArchitectureClaude

backend-architect

31392
from sickn33/antigravity-awesome-skills

Expert backend architect specializing in scalable API design, microservices architecture, and distributed systems.

Software ArchitectureClaude

hybrid-search-implementation

31392
from sickn33/antigravity-awesome-skills

Combine vector and keyword search for improved retrieval. Use when implementing RAG systems, building search engines, or when neither approach alone provides sufficient recall.

Information RetrievalClaude

nft-standards

31392
from sickn33/antigravity-awesome-skills

Master ERC-721 and ERC-1155 NFT standards, metadata best practices, and advanced NFT features.

Web3 & BlockchainClaude

nextjs-app-router-patterns

31392
from sickn33/antigravity-awesome-skills

Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.

Web FrameworksClaude

new-rails-project

31392
from sickn33/antigravity-awesome-skills

Create a new Rails project

Code GenerationClaude

networkx

31392
from sickn33/antigravity-awesome-skills

NetworkX is a Python package for creating, manipulating, and analyzing complex networks and graphs.

Network AnalysisClaude

network-engineer

31392
from sickn33/antigravity-awesome-skills

Expert network engineer specializing in modern cloud networking, security architectures, and performance optimization.

Network EngineeringClaude

nestjs-expert

31392
from sickn33/antigravity-awesome-skills

You are an expert in Nest.js with deep knowledge of enterprise-grade Node.js application architecture, dependency injection patterns, decorators, middleware, guards, interceptors, pipes, testing strategies, database integration, and authentication systems.

Frameworks & LibrariesClaude