projection-patterns
Implement CQRS Projection Patterns
Event-sourced systems need efficient read models for high-performance queries. This skill provides production-ready templates and patterns for building projections, read models, and materialized views from event streams using Python.
Download the skill ZIP
Upload in Claude
Go to Settings → Capabilities → Skills → Upload skill
Toggle on and start using
Test it
Using "projection-patterns". Create a basic order summary projection
Expected outcome:
- Event handler for OrderCreated: Insert new order summary record with customer data
- Event handler for OrderItemAdded: Update total_amount and increment item_count
- Event handler for OrderShipped: Set status to shipped and record shipped_at timestamp
- Checkpoint tracking: Store global_position after each processed event
- Idempotent design: Safe to replay events on system restart
Using "projection-patterns". Build a customer activity tracker projection
Expected outcome:
- CustomerCreated handler: Insert customer record and initialize activity summary
- OrderCompleted handler: Update total_orders and total_spent in summary table
- OrderCompleted handler: Insert into order history table for audit trail
- ReviewSubmitted handler: Increment review count and record last review date
- CustomerTierChanged handler: Update tier and tier change timestamp
Using "projection-patterns". Implement a real-time sales dashboard projection
Expected outcome:
- OrderCompleted handler: Upsert daily sales record with new order totals
- OrderRefunded handler: Decrement revenue and increment refund totals
- Date extraction: Parse completion date to group sales by day
- Atomic updates: Use database ON CONFLICT for race condition safety
- Metric calculations: Track total orders, revenue, items, and refunds per day
Security Audit
Low RiskThis skill is documentation-only containing Python code templates for CQRS projection patterns. Static scanner flagged 42 patterns, but all are false positives triggered by documentation formatting and terminology. No executable code, network calls, or system modifications exist. The skill only provides architectural guidance via markdown templates.
Risk Factors
🌐 Network access (3)
Quality Score
What You Can Build
Build Read Models
Transform event streams into optimized read models for your CQRS architecture.
Create Analytics Views
Build real-time aggregated views for dashboards and reporting systems.
Design Event Systems
Plan and implement projection strategies for event-sourced microservices.
Try These Prompts
Create a basic projection class that handles OrderCreated and OrderCompleted events from an event stream and updates a PostgreSQL read model.
Write a projection that updates both a customer summary table and order history table when an OrderCompleted event occurs, using a single database transaction.
Create an Elasticsearch projection that indexes product events for full-text search, handling create, update, and delete operations.
Write a projection that aggregates sales data by day, handling both completed orders and refunds with upsert logic.
Best Practices
- Make projections idempotent so they can safely replay events after failures or restarts
- Use database transactions when a single event updates multiple related tables
- Store checkpoints to enable resumption from the last processed event position
Avoid
- Coupling projections together creates cascade failures and tight ordering dependencies
- Skipping error handling causes silent failures and data inconsistency in read models
- Over-normalizing read models defeats the purpose of projections by adding join complexity
Frequently Asked Questions
Which databases work with these projections?
How do projections handle high event volumes?
Can I use these patterns with Kafka?
Is my data safe with these projections?
Why is my projection falling behind the event stream?
How is this different from ETL pipelines?
Developer Details
Author
wshobsonLicense
MIT
Repository
https://github.com/wshobson/agents/tree/main/plugins/backend-development/skills/projection-patternsRef
main
File structure
📄 SKILL.md