Cqrs Implementation

作者 wshobson46891e7e60da无许可证收录于 2026年10月8日更新于 2026年10月8日

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

AI 生成的概览

指导实现 CQRS,分离命令与查询模型,并在参考文件中提供模板。

功能
该技能为实现命令查询职责分离(CQRS)架构提供指导。它讲解命令、命令处理器、事件、查询、查询处理器和投影器等核心概念,并列出最佳实践与常见误区。它指向一个参考文件,其中包含模板库和详细示例。
适用场景
适用于分离读写模型、独立扩展读操作、构建事件溯源系统,或优化复杂查询与报表场景。它面向设计与实现指导,而非直接产出代码工件。
运行要求
无需脚本或工具,仅为说明性内容。如需具体模板,建议阅读随附的参考文件 references/details.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
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

来源与署名

来源:wshobson/agents位于plugins/backend-development/skills/cqrs-implementation提交46891e7

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架