技能 projection-patterns
📦

projection-patterns

安全

Build CQRS Projections and Read Models

也可從以下取得: wshobson

Struggling with query performance in event-sourced systems? This skill provides proven patterns for building efficient read models and projections from event streams.

支援: Claude Codex Code(CC)
🥉 75 青銅
1

下載技能 ZIP

2

在 Claude 中上傳

前往 設定 → 功能 → 技能 → 上傳技能

3

開啟並開始使用

測試它

正在使用「projection-patterns」。 User asks for a basic projector template

預期結果:

Provides a Python Projection base class with abstract methods for name, handles(), and apply(). Includes a Projector runner with checkpoint management and batch processing. Shows async/await patterns for database operations.

正在使用「projection-patterns」。 User needs an order summary projection

預期結果:

Delivers OrderSummaryProjection class handling OrderCreated, OrderItemAdded, OrderShipped events. Each handler updates specific columns. Demonstrates parameterized SQL queries and connection pooling.

正在使用「projection-patterns」。 User wants to rebuild a corrupted projection

預期結果:

Explains rebuild process: delete checkpoint, optionally clear read model tables, re-run projection from position 0. Emphasizes idempotency requirement for safe replay.

安全審計

安全
v1 • 2/24/2026

This skill contains documentation and Python code examples for CQRS projection patterns. Static analyzer flagged markdown code blocks as shell commands (false positive). URLs are documentation references, not network calls. No executable code, cryptographic operations, or system access detected. Safe for publication.

2
已掃描檔案
538
分析行數
0
發現項
1
審計總數
未發現安全問題
審計者: claude

品質評分

38
架構
100
可維護性
87
內容
50
社群
100
安全
100
規範符合性

你能建構什麼

E-commerce Order Projections

Build read models that aggregate order events into customer-facing summaries with real-time status updates.

Search Index from Events

Create Elasticsearch projections that keep product catalogs in sync with domain events for full-text search.

Analytics Dashboard Data

Implement aggregating projections that compute daily metrics like sales totals and user activity.

試試這些提示

Basic Projection Setup
I need to build a read model for order events. Show me how to create a basic projector that handles OrderCreated and OrderUpdated events, stores checkpoints, and updates a SQL table.
Elasticsearch Integration
Create a projection that syncs product domain events to Elasticsearch. Include handling for ProductCreated, ProductUpdated, and ProductDeleted events with proper error handling.
Aggregation Pattern
Show me how to build an aggregating projection that computes daily sales metrics from OrderCompleted events. Include UPSERT logic for efficient updates.
Multi-Table Transactional Projection
I need a projection that updates multiple tables atomically when processing CustomerOrderPlaced events. Show transaction handling and rollback patterns.

最佳實務

  • Make projections idempotent - safe to replay events multiple times without side effects
  • Store checkpoints after each event to enable resume after failures
  • Use database transactions for multi-table updates to maintain consistency

避免

  • Coupling projections together - each projection should be independent and isolatable
  • Skipping error handling - unhandled exceptions stop projection and cause data lag
  • Processing events out of order - always respect global_position ordering

常見問題

What is the difference between a projection and a read model?
A projection is the process that transforms events into a read model. The read model is the resulting data structure (database tables, cache, search index) optimized for queries.
How do I handle events that arrive out of order?
Use global_position from the event store to ensure strict ordering. Reject or buffer events that arrive before their predecessors. The event store guarantees order, not the message bus.
Can I rebuild a projection if the read model gets corrupted?
Yes. Delete the projection checkpoint and clear the read model tables, then re-run from position 0. This requires projections to be idempotent.
Should projections be synchronous or asynchronous?
Use asynchronous processing for scalability. Projections typically run as background workers consuming from the event stream, not in the write transaction.
How do I handle projection failures?
Log errors with full event context, alert on repeated failures, and implement retry logic with exponential backoff. Consider a dead-letter queue for poison events.
What database should I use for read models?
Choose based on query patterns: PostgreSQL for relational queries, Elasticsearch for full-text search, Redis for caching, or column stores for analytics. Multiple projections can use different databases.