Projection Patterns

作者 wshobson46891e7e60da無授權條款收錄於 2026年10月8日更新於 2026年10月8日

Build read models and projections from event streams. Use when implementing CQRS read sides, building materialized views, or optimizing query performance in event-sourced systems.

AI 產生的概覽

指導如何在事件溯源系統中從事件串流建構 CQRS 讀取模型與投影。

功能
說明投影架構,展示事件如何從事件存放區經由投影器寫入讀取模型資料庫。介紹即時、追趕、持久化與內嵌等投影類型,並列出關於幂等性、檢查點、順序與重建的最佳實務與常見誤區。指向隨附的參考檔案以取得範本與完整範例。
適用情境
適用於實作 CQRS 讀取端、從事件建構具體化檢視或搜尋索引、最佳化查詢效能,或跨事件串流彙總資料時。也適用於在事件溯源資料上設計即時儀表板。不適用於非事件溯源系統。
執行需求
無需指令碼或工具;這是純說明型技能,並引用隨附的詳細文件。

Projection Patterns

Comprehensive guide to building projections and read models for event-sourced systems.

When to Use This Skill

  • Building CQRS read models
  • Creating materialized views from events
  • Optimizing query performance
  • Implementing real-time dashboards
  • Building search indexes from events
  • Aggregating data across streams

Core Concepts

1. Projection Architecture

┌─────────────┐     ┌─────────────┐     ┌─────────────┐│ Event Store │────►│ Projector   │────►│ Read Model  ││             │     │             │     │ (Database)  ││ ┌─────────┐ │     │ ┌─────────┐ │     │ ┌─────────┐ ││ │ Events  │ │     │ │ Handler │ │     │ │ Tables  │ ││ └─────────┘ │     │ │ Logic   │ │     │ │ Views   │ ││             │     │ └─────────┘ │     │ │ Cache   │ │└─────────────┘     └─────────────┘     └─────────────┘

2. Projection Types

TypeDescriptionUse Case
LiveReal-time from subscriptionCurrent state queries
CatchupProcess historical eventsRebuilding read models
PersistentStores checkpointResume after restart
InlineSame transaction as writeStrong consistency

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

  • Make projections idempotent - Safe to replay
  • Use transactions - For multi-table updates
  • Store checkpoints - Resume after failures
  • Monitor lag - Alert on projection delays
  • Plan for rebuilds - Design for reconstruction

Don'ts

  • Don't couple projections - Each is independent
  • Don't skip error handling - Log and alert on failures
  • Don't ignore ordering - Events must be processed in order
  • Don't over-normalize - Denormalize for query patterns

來源與署名

來源:wshobson/agents位於plugins/backend-development/skills/projection-patterns提交46891e7

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架