{
  "title": "Event Sourcing Pattern",
  "description": "Event sourcing pattern storing all changes as a sequence of events",
  "type": "architecture-pattern",
  "data": {
    "nodes": [
      {
        "id": "service-aggregate",
        "type": "service",
        "position": { "x": 400, "y": 200 },
        "data": {
          "mode": "full",
          "service": {
            "id": "user-aggregate",
            "name": "User Aggregate",
            "owners": ["domain-team"],
            "sends": ["UserCreated", "UserUpdated", "UserDeleted"],
            "receives": ["CreateUser", "UpdateUser", "DeleteUser"],
            "version": "1.0.0",
            "summary": "Domain aggregate that processes commands and emits events"
          }
        },
        "measured": {"width": 262, "height": 113}
      },
      {
        "id": "data-event-store",
        "type": "data",
        "position": { "x": 800, "y": 200 },
        "data": {
          "mode": "full",
          "data": {
            "id": "event-store",
            "name": "Event Store",
            "owners": ["platform-team"],
            "version": "1.0.0",
            "summary": "Append-only store containing all domain events in sequence",
            "type": "Database"
          }
        },
        "measured": {"width": 262, "height": 98}
      },
      {
        "id": "service-projection",
        "type": "service",
        "position": { "x": 1200, "y": 100 },
        "data": {
          "mode": "full",
          "service": {
            "id": "projection-service",
            "name": "Projection Service",
            "owners": ["read-team"],
            "sends": [],
            "receives": ["UserCreated", "UserUpdated", "UserDeleted"],
            "version": "1.0.0",
            "summary": "Builds read models from event stream"
          }
        },
        "measured": {"width": 262, "height": 98}
      },
      {
        "id": "data-read-model",
        "type": "data",
        "position": { "x": 1200, "y": 300 },
        "data": {
          "mode": "full",
          "data": {
            "id": "read-model",
            "name": "Read Model",
            "owners": ["read-team"],
            "version": "1.0.0",
            "summary": "Materialized views built from events for queries",
            "type": "Database"
          }
        },
        "measured": {"width": 262, "height": 98}
      },
      {
        "id": "command-create-user",
        "type": "command",
        "position": { "x": 50, "y": 200 },
        "data": {
          "mode": "full",
          "message": {
            "id": "create-user-command",
            "name": "CreateUser",
            "version": "1.0.0",
            "summary": "Command to create a new user"
          }
        },
        "measured": {"width": 262, "height": 98}
      },
      {
        "id": "event-user-created",
        "type": "event",
        "position": { "x": 800, "y": 50 },
        "data": {
          "mode": "full",
          "message": {
            "id": "user-created",
            "name": "UserCreated",
            "version": "1.0.0",
            "summary": "Event emitted when user is created"
          }
        },
        "measured": {"width": 262, "height": 98}
      },
      {
        "id": "note-event-sourcing-instructions",
        "type": "note",
        "position": { "x": 50, "y": 350 },
        "data": {
          "text": "📚 **Event Sourcing Pattern**\n\nStore all changes as a sequence of events instead of current state:\n\n**📝 Commands** → **🏗️ Aggregate** → **📊 Event Store** → **🔄 Projections** → **📖 Read Models**\n\n**Key Benefits:**\n• **Complete audit trail** - Every change is recorded\n• **Time travel** - Replay events to any point in time\n• **Debugging** - See exactly what happened and when\n• **Flexibility** - Build new read models from existing events\n• **Scalability** - Append-only writes are very fast\n\n**How it works:**\n1. **Commands** sent to domain aggregates\n2. **Aggregates** validate and emit events\n3. **Events** stored in append-only Event Store\n4. **Projections** consume events to build read models\n5. **Queries** served from materialized views\n\n**💡 Pro tip:** Great for audit-heavy domains like finance, but adds complexity - use when you need the benefits!",
          "color": "blue"
        },
        "measured": {"width": 350, "height": 300},
        "width": 350,
        "height": 300
      }
    ],
    "edges": [
      {
        "source": "command-create-user",
        "target": "service-aggregate",
        "label": "Process Command",
        "markerEnd": {"type": "arrowclosed", "color": "#000000"},
        "animated": false,
        "type": "default",
        "id": "xy-edge__command-create-user-service-aggregate"
      },
      {
        "source": "service-aggregate",
        "target": "event-user-created",
        "label": "Emits Event",
        "markerEnd": {"type": "arrowclosed", "color": "#000000"},
        "animated": true,
        "type": "animatedMessage",
        "id": "xy-edge__service-aggregate-event-user-created"
      },
      {
        "source": "event-user-created",
        "target": "data-event-store",
        "label": "Stored in",
        "markerEnd": {"type": "arrowclosed", "color": "#000000"},
        "animated": true,
        "type": "animatedMessage",
        "id": "xy-edge__event-user-created-data-event-store"
      },
      {
        "source": "data-event-store",
        "target": "service-projection",
        "label": "Event Stream",
        "markerEnd": {"type": "arrowclosed", "color": "#000000"},
        "animated": true,
        "type": "animatedMessage",
        "id": "xy-edge__data-event-store-service-projection"
      },
      {
        "source": "service-projection",
        "target": "data-read-model",
        "label": "Updates",
        "markerEnd": {"type": "arrowclosed", "color": "#000000"},
        "animated": false,
        "type": "default",
        "id": "xy-edge__service-projection-data-read-model"
      }
    ],
    "viewport": {"x": 50, "y": 50, "zoom": 0.7},
    "creationDate": "2025-01-01T00:00:00.000Z",
    "name": "Event Sourcing Pattern",
    "version": "1.0.0",
    "source": "https://eventcatalog.dev",
    "appState": {},
    "id": "event-sourcing-pattern"
  },
  "usecase": "Design Event Sourcing Architecture",
  "mermaid": "flowchart LR\n    C[Command] --> A[Aggregate]\n    A --> E[Events]\n    E --> ES[(Event Store)]\n    ES --> P[Projections]\n    P --> V[Views]",
  "tags": ["Event-Driven"]
}