---
name: patrones-proyeccion-event-sourcing
description: Guía completa para construir modelos de lectura y proyecciones desde flujos de eventos en sistemas CQRS. Cubre tipos de proyección, arquitectura, buenas prácticas e idempotencia.
license: MIT
metadata:
  id: df6f9b91
  slug: patrones-proyeccion-event-sourcing
  titulo: "Patrones de Proyección para Event Sourcing"
  servicio: Web
  categoria_recurso: Inspiracion-Formacion
  tipo: referencia
  nivel: avanzado
  idioma: es
  idioma_original: en
  acceso: gratis
  precio_eur: 0
  plataformas: [agnóstico]
  dependencias: []
  licencia: { spdx: MIT, redistribuible: true, uso_comercial: true }
  fuente:
    repo: wshobson/agents
    url: https://github.com/wshobson/agents/tree/main/plugins/backend-development/skills/projection-patterns
    commit: cc37bfd
    autor: wshobson
    nombre_original: projection-patterns
    duplicados_en: []
  seguridad: { veredicto: seguro, riesgo: bajo, escaneado: "2026-06-14", motor: "grep-estatico+auditor-llm" }
  ficha:
    que_hace: "Enseña a construir proyecciones y modelos de lectura optimizados a partir de flujos de eventos en arquitecturas CQRS/Event Sourcing."
    como_lo_hace: "Proporciona una guía de referencia con arquitectura visual, tabla de tipos de proyección (Live, Catchup, Persistent, Inline) y buenas prácticas de idempotencia y checkpointing."
  content_hash: "df6f9b9182a860b0bb295344c10aa8fd4611b94341077c6a2dbf525a9f5fea2d"
  version: 1.0.0
---

# 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

| Type           | Description                 | Use Case               |
| -------------- | --------------------------- | ---------------------- |
| **Live**       | Real-time from subscription | Current state queries  |
| **Catchup**    | Process historical events   | Rebuilding read models |
| **Persistent** | Stores checkpoint           | Resume after restart   |
| **Inline**     | Same transaction as write   | Strong 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
