{
  "title": "Saga Pattern",
  "description": "Models a distributed transaction using the Saga pattern with compensation actions",
  "type": "architecture-pattern",
  "data": {
    "nodes": [
      {
        "id": "service-order",
        "type": "service",
        "position": {
          "x": 100,
          "y": 200
        },
        "data": {
          "mode": "full",
          "service": {
            "id": "order-service",
            "name": "Order Service",
            "owners": ["order-team"],
            "sends": ["OrderCreated", "OrderCancelled"],
            "receives": ["CreateOrder", "CancelOrder"],
            "version": "1.0.0",
            "summary": "Manages customer orders and initiates saga orchestration"
          },
          "editor": {
            "title": "Service",
            "subtitle": "Edit the details of the service",
            "schema": {
              "type": "object",
              "required": ["service", "mode"],
              "properties": {
                "service": {
                  "type": "object",
                  "required": ["name", "version"],
                  "properties": {
                    "name": {"type": "string", "title": "Name", "default": "Random value", "description": "The name of the service"},
                    "version": {"type": "string", "title": "Version", "default": "1.0.0", "description": "The version number (e.g., 1.0.0)", "pattern": "^\\\\d+\\\\.\\\\d+\\\\.\\\\d+(?:-[\\\\w.-]+)?(?:\\\\+[\\\\w.-]+)?$"},
                    "summary": {"type": "string", "title": "Summary", "default": "", "description": "A brief summary of the service"}
                  }
                }
              }
            }
          }
        },
        "measured": {"width": 262, "height": 113},
        "selected": false,
        "dragging": false
      },
      {
        "id": "service-payment",
        "type": "service",
        "position": {
          "x": 500,
          "y": 100
        },
        "data": {
          "mode": "full",
          "service": {
            "id": "payment-service",
            "name": "Payment Service",
            "owners": ["payment-team"],
            "sends": ["PaymentProcessed", "PaymentFailed", "PaymentRefunded"],
            "receives": ["ProcessPayment", "RefundPayment"],
            "version": "1.0.0",
            "summary": "Handles payment processing and refunds in saga transactions"
          },
          "editor": {
            "title": "Service",
            "subtitle": "Edit the details of the service",
            "schema": {
              "type": "object",
              "required": ["service", "mode"],
              "properties": {
                "service": {
                  "type": "object",
                  "required": ["name", "version"],
                  "properties": {
                    "name": {"type": "string", "title": "Name", "default": "Random value", "description": "The name of the service"},
                    "version": {"type": "string", "title": "Version", "default": "1.0.0", "description": "The version number (e.g., 1.0.0)", "pattern": "^\\\\d+\\\\.\\\\d+\\\\.\\\\d+(?:-[\\\\w.-]+)?(?:\\\\+[\\\\w.-]+)?$"},
                    "summary": {"type": "string", "title": "Summary", "default": "", "description": "A brief summary of the service"}
                  }
                }
              }
            }
          }
        },
        "measured": {"width": 262, "height": 98},
        "selected": false,
        "dragging": false
      },
      {
        "id": "service-inventory",
        "type": "service",
        "position": {
          "x": 500,
          "y": 300
        },
        "data": {
          "mode": "full",
          "service": {
            "id": "inventory-service",
            "name": "Inventory Service",
            "owners": ["inventory-team"],
            "sends": ["InventoryReserved", "InventoryReservationFailed", "InventoryReleased"],
            "receives": ["ReserveInventory", "ReleaseInventory"],
            "version": "1.0.0",
            "summary": "Manages inventory reservations and releases with compensation logic"
          },
          "editor": {
            "title": "Service",
            "subtitle": "Edit the details of the service",
            "schema": {
              "type": "object",
              "required": ["service", "mode"],
              "properties": {
                "service": {
                  "type": "object",
                  "required": ["name", "version"],
                  "properties": {
                    "name": {"type": "string", "title": "Name", "default": "Random value", "description": "The name of the service"},
                    "version": {"type": "string", "title": "Version", "default": "1.0.0", "description": "The version number (e.g., 1.0.0)", "pattern": "^\\\\d+\\\\.\\\\d+\\\\.\\\\d+(?:-[\\\\w.-]+)?(?:\\\\+[\\\\w.-]+)?$"},
                    "summary": {"type": "string", "title": "Summary", "default": "", "description": "A brief summary of the service"}
                  }
                }
              }
            }
          }
        },
        "measured": {"width": 262, "height": 98},
        "selected": false,
        "dragging": false
      },
      {
        "id": "service-saga-orchestrator",
        "type": "service",
        "position": {
          "x": 900,
          "y": 200
        },
        "data": {
          "mode": "full",
          "service": {
            "id": "saga-orchestrator",
            "name": "Saga Orchestrator",
            "owners": ["platform-team"],
            "sends": ["ProcessPayment", "ReserveInventory", "RefundPayment", "ReleaseInventory"],
            "receives": ["PaymentProcessed", "PaymentFailed", "InventoryReserved", "InventoryReservationFailed"],
            "version": "1.0.0",
            "summary": "Orchestrates distributed transactions and handles compensation logic"
          },
          "editor": {
            "title": "Service",
            "subtitle": "Edit the details of the service",
            "schema": {
              "type": "object",
              "required": ["service", "mode"],
              "properties": {
                "service": {
                  "type": "object",
                  "required": ["name", "version"],
                  "properties": {
                    "name": {"type": "string", "title": "Name", "default": "Random value", "description": "The name of the service"},
                    "version": {"type": "string", "title": "Version", "default": "1.0.0", "description": "The version number (e.g., 1.0.0)", "pattern": "^\\\\d+\\\\.\\\\d+\\\\.\\\\d+(?:-[\\\\w.-]+)?(?:\\\\+[\\\\w.-]+)?$"},
                    "summary": {"type": "string", "title": "Summary", "default": "", "description": "A brief summary of the service"}
                  }
                }
              }
            }
          }
        },
        "measured": {"width": 262, "height": 113},
        "selected": false,
        "dragging": false
      },
      {
        "id": "event-payment-processed",
        "type": "event",
        "position": {
          "x": 750,
          "y": 50
        },
        "data": {
          "mode": "full",
          "message": {
            "id": "payment-processed",
            "name": "PaymentProcessed",
            "version": "1.0.0",
            "summary": "Event indicating successful payment processing in saga"
          },
          "editor": {
            "title": "Event",
            "subtitle": "Edit the details of the event",
            "schema": {
              "type": "object",
              "required": ["message", "mode"],
              "properties": {
                "message": {
                  "type": "object",
                  "required": ["name", "version"],
                  "properties": {
                    "name": {"type": "string", "title": "Name", "default": "Random value", "description": "The name of the event"},
                    "version": {"type": "string", "title": "Version", "default": "1.0.0", "description": "The version number (e.g., 1.0.0)", "pattern": "^\\\\d+\\\\.\\\\d+\\\\.\\\\d+(?:-[\\\\w.-]+)?(?:\\\\+[\\\\w.-]+)?$"},
                    "summary": {"type": "string", "title": "Summary", "default": "", "description": "A brief summary of the event"}
                  }
                }
              }
            }
          }
        },
        "measured": {"width": 262, "height": 98},
        "selected": false,
        "dragging": false
      },
      {
        "id": "event-inventory-reserved",
        "type": "event",
        "position": {
          "x": 750,
          "y": 350
        },
        "data": {
          "mode": "full",
          "message": {
            "id": "inventory-reserved",
            "name": "InventoryReserved",
            "version": "1.0.0",
            "summary": "Event indicating successful inventory reservation in saga"
          },
          "editor": {
            "title": "Event",
            "subtitle": "Edit the details of the event",
            "schema": {
              "type": "object",
              "required": ["message", "mode"],
              "properties": {
                "message": {
                  "type": "object",
                  "required": ["name", "version"],
                  "properties": {
                    "name": {"type": "string", "title": "Name", "default": "Random value", "description": "The name of the event"},
                    "version": {"type": "string", "title": "Version", "default": "1.0.0", "description": "The version number (e.g., 1.0.0)", "pattern": "^\\\\d+\\\\.\\\\d+\\\\.\\\\d+(?:-[\\\\w.-]+)?(?:\\\\+[\\\\w.-]+)?$"},
                    "summary": {"type": "string", "title": "Summary", "default": "", "description": "A brief summary of the event"}
                  }
                }
              }
            }
          }
        },
        "measured": {"width": 262, "height": 98},
        "selected": false,
        "dragging": false
      },
      {
        "id": "note-saga-instructions",
        "type": "note",
        "position": {
          "x": 100,
          "y": 450
        },
        "data": {
          "text": "🔄 **Saga Pattern**\n\nDistributed transaction pattern ensuring data consistency across microservices:\n\n**🛍️ Order Service** → **🎭 Saga Orchestrator** → **💳 Payment Service** & **📦 Inventory Service**\n\n**How Saga Works:**\n1. **Order Service** initiates saga transaction\n2. **Saga Orchestrator** coordinates all steps\n3. **Payment Service** processes payment\n4. **Inventory Service** reserves items\n5. **Compensations** run if any step fails\n\n**Key Benefits:**\n• **ACID across services** - Maintains consistency without distributed transactions\n• **Failure recovery** - Automatic compensation actions\n• **Loose coupling** - Services remain independent\n• **Observability** - Clear transaction state tracking\n\n**💡 Pro tip:** Use orchestration for complex workflows, choreography for simple ones!",
          "color": "purple"
        },
        "measured": {"width": 320, "height": 280},
        "selected": false,
        "dragging": false,
        "width": 320,
        "height": 280,
        "resizing": false
      }
    ],
    "edges": [
      {
        "source": "service-order",
        "target": "service-saga-orchestrator",
        "label": "Initiates Saga",
        "markerEnd": {"type": "arrowclosed", "color": "#000000"},
        "animated": true,
        "type": "animatedMessage",
        "data": {"source": "service", "target": "service", "message": {"collection": "commands", "opacity": 1}},
        "id": "xy-edge__service-order-service-saga-orchestrator"
      },
      {
        "source": "service-saga-orchestrator",
        "target": "service-payment",
        "label": "Process Payment",
        "markerEnd": {"type": "arrowclosed", "color": "#000000"},
        "animated": true,
        "type": "animatedMessage",
        "data": {"source": "service", "target": "service", "message": {"collection": "commands", "opacity": 1}},
        "id": "xy-edge__service-saga-orchestrator-service-payment"
      },
      {
        "source": "service-saga-orchestrator",
        "target": "service-inventory",
        "label": "Reserve Inventory",
        "markerEnd": {"type": "arrowclosed", "color": "#000000"},
        "animated": true,
        "type": "animatedMessage",
        "data": {"source": "service", "target": "service", "message": {"collection": "commands", "opacity": 1}},
        "id": "xy-edge__service-saga-orchestrator-service-inventory"
      },
      {
        "source": "service-payment",
        "target": "event-payment-processed",
        "label": "Publishes",
        "markerEnd": {"type": "arrowclosed", "color": "#000000"},
        "animated": true,
        "type": "animatedMessage",
        "data": {"source": "service", "target": "event", "message": {"collection": "events", "opacity": 1}},
        "id": "xy-edge__service-payment-event-payment-processed"
      },
      {
        "source": "service-inventory",
        "target": "event-inventory-reserved",
        "label": "Publishes",
        "markerEnd": {"type": "arrowclosed", "color": "#000000"},
        "animated": true,
        "type": "animatedMessage",
        "data": {"source": "service", "target": "event", "message": {"collection": "events", "opacity": 1}},
        "id": "xy-edge__service-inventory-event-inventory-reserved"
      },
      {
        "source": "event-payment-processed",
        "target": "service-saga-orchestrator",
        "label": "Consumed by",
        "markerEnd": {"type": "arrowclosed", "color": "#000000"},
        "animated": true,
        "type": "animatedMessage",
        "data": {"source": "event", "target": "service", "message": {"collection": "events", "opacity": 1}},
        "id": "xy-edge__event-payment-processed-service-saga-orchestrator"
      },
      {
        "source": "event-inventory-reserved",
        "target": "service-saga-orchestrator",
        "label": "Consumed by",
        "markerEnd": {"type": "arrowclosed", "color": "#000000"},
        "animated": true,
        "type": "animatedMessage",
        "data": {"source": "event", "target": "service", "message": {"collection": "events", "opacity": 1}},
        "id": "xy-edge__event-inventory-reserved-service-saga-orchestrator"
      }
    ],
    "viewport": {"x": 50, "y": 50, "zoom": 0.7},
    "creationDate": "2025-01-01T00:00:00.000Z",
    "name": "Saga Pattern",
    "version": "1.0.0",
    "source": "https://eventcatalog.dev",
    "appState": {},
    "id": "saga-pattern"
  },
  "usecase": "Design Distributed Transactions",
  "mermaid": "flowchart TD\n    O[Order] --> S[Saga]\n    S --> P[Payment]\n    S --> I[Inventory]\n    P --> S\n    I --> S",
  "tags": ["Distributed Systems"]
}