patterns
できること
このドキュメントは、CQRS、Event Sourcing、Sagaなど、プログラミングで使われる設計パターンのリファレンスです。それぞれが何か、いつ使うのか、どのように動くのかを説明しています。
使う場面
- ✓設計パターンについて学びたいとき。
- ✓複雑なシステムをどのように整理するかを理解したいとき。
- ✓よくあるソフトウェアの問題に対する解決策を探しているとき。
スキルのリンク
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/monopoly/patterns/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“Circuit Breakerパターンについて説明してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
このドキュメントでは、さまざまなソフトウェア設計パターンを一覧にして解説しています。各パターンについて、何か、いつ役立つか、どのように実装するか、そしてメリットとデメリットを詳しく紹介しています。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
MONOPOLY — Design Patterns Deep Dive
When to Use
- Use this skill when the task matches this description: Reference document for monopoly patterns.
Table of Contents
- CQRS
- Event Sourcing
- Saga Pattern
- Circuit Breaker
- Bulkhead
- Strangler Fig
- Sidecar / Service Mesh
- Outbox Pattern
- Consistent Hashing
- Backpressure
- Leader Election
- Two-Phase Commit
1. CQRS (Command Query Responsibility Segregation)
What it is: Separate the read model (Query) from the write model (Command) into distinct services, databases, or code paths.
When to use:
- Read load is 10×+ write load (most web apps)
- Read queries are complex aggregations over write data
- Need to optimize read and write paths independently
- Domain model is complex (DDD contexts)
Implementation:
Write Path: Client → Command API → Write DB (normalized, PostgreSQL)
Read Path: Client → Query API → Read DB (denormalized, Redis / Elasticsearch)
Sync: Write DB → CDC (Debezium) → Message Queue → Read DB updater
Trade-offs:
- ✅ Independent scaling of read and write
- ✅ Optimized schemas for each operation type
- ❌ Eventual consistency between write and read models
- ❌ Increased complexity; two models to maintain
Real-world users: Amazon (order service), LinkedIn (feed)
2. Event Sourcing
What it is: Store state as a sequence of immutable events rather than current state. Rebuild current state by replaying events.
When to use:
- Full audit trail is a regulatory requirement (fintech, healthcare)
- Need to replay history for debugging or analytics
- Complex domain with many state transitions
- Need to derive multiple read projections from same data
Implementation:
Event Store: append-only log (Kafka, EventStoreDB)
Snapshots: periodic snapshots to speed up state rebuild
Projections: consumers build read models from events
Trade-offs:
- ✅ Complete audit history; perfect for compliance
- ✅ Replay and time-travel debugging
- ❌ Querying current state requires projection maintenance
- ❌ Event schema evolution is hard
- ❌ High storage overhead over time
3. Saga Pattern
What it is: Manage distributed transactions across microservices via a sequence of local transactions, each publishing an event. If a step fails, compensating transactions undo previous steps.
Two variants:
- Choreography: Services react to events autonomously (decentralized)
- Orchestration: A central Saga Orchestrator coordinates steps (centralized)
When to use:
- Multi-service workflows where ACID across services is impossible
- Long-running business transactions (order → payment → inventory → shipping)
- Need rollback across service boundaries
Choreography Example:
OrderService creates order →
[event: OrderCreated] →
PaymentService charges card →
[event: PaymentProcessed] →
InventoryService reserves stock →
[event: StockReserved] →
ShippingService books courier
Compensating Transactions (on failure):
ShippingService fails →
[event: ShippingFailed] →
InventoryService releases stock →
PaymentService refunds card →
OrderService marks order failed
Trade-offs:
- ✅ No distributed locking; high availability
- ✅ Scales well across services
- ❌ Hard to debug; distributed trace required
- ❌ Compensating transactions are complex to implement correctly
4. Circuit Breaker
What it is: A proxy that monitors calls to a service. If failure rate exceeds threshold, the circuit "opens" and calls fail fast instead of waiting for timeout.
States:
CLOSED → calls pass through; monitor failure rate
OPEN → calls fail immediately; no calls to downstream
HALF-OPEN → let a probe call through; if success, close; if fail, stay open
When to use:
- Calling any external service (payment gateway, SMS, email)
- Microservices calling each other
- Preventing timeout cascade when downstream is slow
Implementation tools: Hystrix (deprecated), Resilience4j, Polly (.NET), Envoy proxy
Thresholds (starting point):
- Open after 50% failure rate over 10 requests
- Stay open for 30 seconds
- Half-open: allow 1 probe request
Trade-offs:
- ✅ Prevents cascade failures
- ✅ Gives downstream time to recover
- ❌ Adds latency overhead for monitoring
- ❌ Requires fallback behavior when circuit is open
5. Bulkhead
…
よくある質問
「設計パターン」とは何ですか?
ソフトウェア開発でよく直面する問題に対する、再利用可能な解決策のことです。より整理されていて、効率がよく、保守しやすいコードを作るのに役立ちます。
CQRSとEvent Sourcingの違いは何ですか?
CQRSは読み取り処理と書き込み処理を分離する考え方です。一方、Event Sourcingはすべての変更を一連のイベントとして記録します。
「Sagaパターン」とは何ですか?
複数のサービスにまたがるトランザクションを管理する方法です。一部が失敗しても、すべての処理が完了するか、正しく巻き戻されるようにします。
詳細
人気
- GitHubのスター
- 48k
- ランキング
- #5233
- ライセンス
- MIT
- 更新日
- 2026/10/15
コメント
- …
このリポジトリの他のスキル
00-andruia-consultant
48kエージェントがAIプロジェクトの立ち上げや改善を支援します。コードを分析し、ツールを提案し、スペイン語で行動計画を作成します。
007
48kエージェントがセキュリティ監査と脅威モデリングを行えるようにします。攻撃や脆弱性からプロジェクトを守るのに役立ちます。
10-andruia-skill-smith
48kエージェントがAIツールの作成や改善を支援します。ツールの動作を定義し、ドキュメントを書き、構造を検証します。
20-andruia-niche-intelligence
48kエージェントが特定の業界に関する要約を作成できるようにします。信頼できる情報源を使って、プロジェクトの背景、ルール、利用パターン、リスクを把握するのに役立ちます。