CQRS (Command Query Responsibility Segregation) patterns for separating read and write models. Use when optimizing read-heavy systems, implementing event sourcing, or building systems with different read/write scaling requirements.
View on GitHubyonatangross/orchestkit
orchestkit-complete
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/yonatangross/orchestkit/blob/main/./skills/cqrs-patterns/SKILL.md -a claude-code --skill cqrs-patternsInstallation paths:
.claude/skills/cqrs-patterns/# CQRS Patterns
Separate read and write concerns for optimized data access.
## Overview
- Read-heavy workloads with complex queries
- Different scaling requirements for reads vs writes
- Event sourcing implementations
- Multiple read model representations of same data
- Complex domain models with simple read requirements
## When NOT to Use
- Simple CRUD applications
- Strong consistency requirements everywhere
- Small datasets with simple queries
## Architecture Overview
```
┌─────────────────┐ ┌─────────────────┐
│ Write Side │ │ Read Side │
├─────────────────┤ ├─────────────────┤
│ ┌───────────┐ │ │ ┌───────────┐ │
│ │ Commands │ │ │ │ Queries │ │
│ └─────┬─────┘ │ │ └─────┬─────┘ │
│ ┌─────▼─────┐ │ │ ┌─────▼─────┐ │
│ │ Aggregate │ │ │ │Read Model │ │
│ └─────┬─────┘ │ │ └───────────┘ │
│ ┌─────▼─────┐ │ │ ▲ │
│ │ Events │──┼─────────┼────────┘ │
│ └───────────┘ │ Publish │ Project │
└─────────────────┘ └─────────────────┘
```
## Command Side (Write Model)
### Command and Handler
```python
from pydantic import BaseModel, Field
from uuid import UUID, uuid4
from datetime import datetime, timezone
from abc import ABC, abstractmethod
class Command(BaseModel):
"""Base command with metadata."""
command_id: UUID = Field(default_factory=uuid4)
timestamp: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
user_id: UUID | None = None
class CreateOrder(Command):
customer_id: UUID
items: list[OrderItem]
shipping_address: Address
class CommandHandler(ABC):
@abstractmethod
async def handle(self, command: Command) -> list["DomainEvent"]:
pass
class CreateOrderHandler(CommandHandler):
def __init__(self, order_repo, inventory_service):
self.order_repo = order_repo
self.inventory = inventory_service
async def handle(self