本文へスキップ
Skillpedia
APIとサーバー(バックエンド)41k · #6637

cqrs-implementation

できること

このガイドは、システムにおけるデータの書き込みと読み取りの処理を分けて実装する方法を解説します。特に多くの情報が参照・更新される場合に、システムを速く、整理された状態に保つのに役立ちます。

使う場面

  • ✓データの書き込みと読み取りを、それぞれ別の方法で動かす必要があるとき
  • ✓書き込み処理に影響を与えずに、読み取り部分の速度を上げたいとき
  • ✓すべての変更をイベントとして記録するシステムを作るとき

スキルのリンク

https://github.com/wshobson/agents/blob/main/plugins/backend-development/skills/cqrs-implementation/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/wshobson/agents/blob/main/plugins/backend-development/skills/cqrs-implementation/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“CQRSを使って、複雑なレポートの表示速度を最適化するにはどうすればよいですか?”

毎週5つの新しいスキル。1分で読めます。

仕組み

処理を「コマンド」(データを変更する操作)と「クエリ」(データを読み取る操作)の2つに分けて行います。それぞれを別々のデータモデルを使って、性能を重視しながら個別に最適化できます。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

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

Component Responsibility
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.

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
よくある質問

「結果整合性(eventual consistency)」とは何ですか?

システムの各部分にデータが反映されるまでに少し時間がかかることがあるものの、最終的には正しい状態になるという意味です。

読み取り用のモデルと書き込み用のモデルを分けるのはなぜですか?

両者では必要とされることが異なるからです。書き込みモデルはデータの整合性を確実に保つ必要があり、読み取りモデルは問い合わせに素早く答えられることが求められます。

シンプルな実装から始めてもよいですか?

はい。まずはシンプルに始め、本当に必要になったときにだけ複雑さを加えるのがおすすめです。

詳細

作者による元の説明

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

repo: wshobson/agents

人気

GitHubのスター
41k
ランキング
#6637
ライセンス
MIT
更新日
2026/10/15

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル