Projection Patterns

by wshobson46891e7e60daNo licenseListed Oct 8, 2026Updated Oct 8, 2026

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.

Instructions onlySoftware Development
AI-generated overview

Guidance for building CQRS read models and projections from event streams in event-sourced systems.

What it does
Explains projection architecture, showing how events flow from an event store through a projector into a read model database. Describes projection types such as live, catchup, persistent and inline, and lists best practices and pitfalls for idempotency, checkpoints, ordering and rebuilds. Points to a bundled reference file for templates and worked examples.
When to use it
Use when implementing the read side of CQRS, building materialized views or search indexes from events, optimizing query performance, or aggregating data across event streams. Also relevant when designing real-time dashboards on event-sourced data. Not a fit for systems that are not event-sourced.
Requirements
No scripts or tools required; it is an instructions-only skill that references a bundled details document.

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

Source and attribution

Source:wshobson/agentsinplugins/backend-development/skills/projection-patternsat commit46891e7

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal