PluginBench
Skill
Pass
Audit score 90

projection-patterns

wshobson/agents

Build read models and projections from event streams for CQRS and event-sourced systems.

What is projection-patterns?

Comprehensive guide to implementing projections and materialized views that transform event streams into optimized read models. Use this skill when building CQRS architectures, creating real-time dashboards, or optimizing query performance in event-sourced systems.

  • Design projection architectures that consume event streams and populate read models
  • Implement live, catchup, persistent, and inline projection types for different consistency requirements
  • Create idempotent projections safe for replay and rebuilding
  • Store checkpoints to resume processing after failures
  • Build materialized views and search indexes from events
  • Handle multi-table updates with transactions

How to install projection-patterns

npx skills add https://github.com/wshobson/agents --skill projection-patterns
Prerequisites
  • Event store or event stream infrastructure
  • Database or cache for storing read models
  • Understanding of event sourcing concepts
Claude Code
Cursor
Windsurf
Cline

How to use projection-patterns

  1. 1.Review projection types (live, catchup, persistent, inline) to choose the right pattern for your consistency requirements
  2. 2.Design your read model schema based on query patterns, denormalizing as needed
  3. 3.Implement projection handlers that transform events into read model updates
  4. 4.Add checkpoint storage to track processing progress and enable resumption
  5. 5.Set up monitoring to alert on projection lag or processing failures
  6. 6.Test idempotency by replaying projections multiple times
  7. 7.Plan and test rebuild procedures for reconstructing read models from events

Use cases

Good for
  • Implementing CQRS read sides that serve optimized queries independently from the write model
  • Creating real-time dashboards that update as events flow through the system
  • Rebuilding materialized views and read models from historical event streams
  • Building search indexes from domain events for fast text or faceted search
  • Aggregating data across multiple event streams into denormalized views
Who it's for
  • Backend engineers implementing event-sourced systems
  • CQRS architects designing read and write model separation
  • Database designers optimizing query performance
  • System engineers building real-time data pipelines

projection-patterns FAQ

What's the difference between live and catchup projections?

Live projections process events in real-time from a subscription, ideal for current state queries. Catchup projections process historical events from the beginning, used for rebuilding read models or catching up after downtime.

Why must projections be idempotent?

Idempotent projections can safely handle duplicate events or replays without corrupting data. This is essential for reliability when events may be delivered multiple times or when rebuilding read models.

How do I handle projection failures?

Store checkpoints to track which events have been processed. On failure, resume from the last checkpoint rather than reprocessing all events. Log failures and alert operators for investigation.

Should I normalize or denormalize my read models?

Denormalize read models based on your query patterns. Unlike write models, read models optimize for query performance, not storage efficiency. Include all data needed for queries in a single table or view.

Can multiple projections consume the same event stream?

Yes, projections are independent. Multiple projections can subscribe to the same event stream and build different read models for different query patterns.

Full instructions (SKILL.md)

Source of truth, from wshobson/agents.


name: projection-patterns description: 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.

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