Inferensys

Prompt

Saga Orchestration Flow Design Prompt

A practical prompt playbook for using the Saga Orchestration Flow Design Prompt in production AI workflows to review step sequencing, compensation logic, and failure recovery.
Developer designing multi-agent workflow on laptop, architecture diagram on screen, casual home office setup with afternoon light.
PROMPT PLAYBOOK

When to Use This Prompt

Define the job, reader, and constraints for the Saga Orchestration Flow Design Prompt.

This prompt is for architects and backend engineers who are designing a distributed transaction that spans multiple services and must maintain data consistency without relying on traditional ACID transactions. The job-to-be-done is a structured design review of a saga orchestration flow before a single line of code is written. You should use this prompt when you have a concrete business process—such as order fulfillment, payment processing with inventory reservation, or multi-service account provisioning—that requires a sequence of local transactions with compensating actions for rollback. The ideal user has already mapped the high-level steps and is now ready to pressure-test the flow for missing compensation logic, orphaned state, timeout handling, and failure recovery gaps.

Do not use this prompt for simple request-response workflows, single-service operations, or processes where eventual consistency is acceptable without explicit rollback. It is also not a replacement for a choreography-based event design review; if your services communicate through broadcasted events without a central coordinator, use the Choreography vs Orchestration Decision Prompt instead. This prompt assumes an orchestrator pattern where one service directs the saga. You will need to provide the sequence of steps, the compensation action for each step, timeout thresholds, and any idempotency or retry policies already in place. The prompt works best when you supply a concrete flow diagram or step list rather than an abstract description.

After running this prompt, you will receive a structured review that identifies missing compensation steps, orphaned state risks, timeout handling gaps, and failure state recovery weaknesses. The output is designed to be actionable: each finding includes a severity, a rationale, and a suggested remediation. Before you integrate the output into your design document, validate that every identified gap maps to a real step in your flow and that no false positives have been introduced by ambiguous step naming. For high-risk financial or compliance workflows, always have a second architect review the findings before finalizing the saga design.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Saga Orchestration Flow Design Prompt works, where it fails, and what you must provide before running it. This prompt is a design review tool, not a runtime orchestrator.

01

Good Fit: Greenfield Saga Design

Use when: designing a new distributed transaction from scratch with clear step boundaries. The prompt excels at generating a first-pass orchestration plan with compensating actions for each step. Guardrail: always review generated compensation logic against actual business reversal rules—the model may propose technically correct but legally invalid rollbacks.

02

Good Fit: Existing Saga Audit

Use when: reviewing an implemented saga for missing compensation steps or orphaned state. Feed the current step definitions and let the prompt identify gaps. Guardrail: provide the actual implementation code or config, not just documentation—docs often omit edge cases the prompt needs to catch.

03

Bad Fit: Real-Time Orchestration

Avoid when: you need a runtime engine to execute saga steps. This prompt produces a design document, not executable workflow logic. Guardrail: use this output as input to a proper saga framework like Temporal, Camunda, or AWS Step Functions—never attempt to drive production orchestration from LLM output directly.

04

Required Input: Step Inventory

What to watch: the prompt cannot invent your business steps. It needs a complete list of participating services, their operations, and failure modes. Guardrail: provide a structured step inventory with service names, operation signatures, idempotency status, and known failure modes before running the prompt. Missing inputs produce plausible but incorrect sagas.

05

Required Input: Timeout Constraints

What to watch: sagas without timeout specifications produce designs that hang indefinitely. The prompt needs per-step timeout expectations and overall saga SLA. Guardrail: include explicit timeout values and the business impact of exceeding them. The prompt should flag steps where timeout handling is undefined.

06

Operational Risk: Compensation Gaps

What to watch: the most common failure mode is missing or incorrect compensating actions. The prompt may omit compensation for steps that appear idempotent but have side effects. Guardrail: run the output through the companion eval harness that checks every forward step has a defined compensation, and manually verify compensations that touch external systems or payment rails.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A reusable prompt template for generating a structured saga orchestration design review, ready to be copied and adapted with your specific context.

This prompt template is the core engine of the playbook. It instructs the model to act as a distributed systems architect and produce a rigorous review of a proposed saga orchestration flow. The template uses square-bracket placeholders for all variable inputs, making it safe to inject into a production system without accidental tokenization issues. You should fill these placeholders with your specific saga definition, business context, and output requirements before sending the prompt to the model.

text
You are a principal distributed systems architect reviewing a saga orchestration design for a microservices environment. Your task is to produce a structured design review that identifies risks, gaps, and failure modes before implementation.

## SAGA DEFINITION
[SAGA_NAME]: [SAGA_DESCRIPTION]

[SAGA_STEPS]

## BUSINESS CONTEXT
[CONSISTENCY_REQUIREMENTS]
[TIMEOUT_CONSTRAINTS]
[CRITICALITY_LEVEL]

## REVIEW INSTRUCTIONS
Analyze the saga definition and produce a review with the following sections. Be specific and critical. If a section has no findings, state that explicitly.

1.  **Step Sequencing Analysis**: Evaluate the order of steps. Are there any steps that should be reordered to reduce the window of inconsistency? Identify any implicit assumptions about synchronous vs. asynchronous execution.
2.  **Compensation Logic Audit**: For every step that has a side effect, verify that a corresponding compensation step is defined. Flag any missing compensations. Assess the idempotency of each compensation step.
3.  **Failure State and Timeout Handling**: Analyze the defined behavior for step timeouts, service unavailability, and permanent failures. Identify scenarios that could lead to orphaned state or incomplete transactions. Evaluate the retry strategy for each step.
4.  **Orphaned State and Recovery**: Identify any failure scenarios where the saga could terminate but leave resources in an inconsistent state (e.g., a payment captured but an order not created). Propose a recovery mechanism or manual intervention point.
5.  **Observability and Operational Readiness**: Assess the design's traceability. Are correlation IDs propagated? Are there clear points to log the saga's progress, state transitions, and compensation actions? Identify observability gaps that would make debugging a production failure difficult.

## OUTPUT FORMAT
Return your review as a JSON object with the following schema:
{
  "saga_name": "string",
  "overall_risk_assessment": "low" | "medium" | "high" | "critical",
  "step_sequencing_analysis": {
    "findings": [{"severity": "string", "description": "string", "recommendation": "string"}],
    "overall_assessment": "string"
  },
  "compensation_logic_audit": {
    "missing_compensations": [{"step": "string", "risk": "string"}],
    "idempotency_concerns": [{"step": "string", "issue": "string"}],
    "overall_assessment": "string"
  },
  "failure_state_analysis": {
    "orphaned_state_scenarios": [{"scenario": "string", "impact": "string", "recovery_suggestion": "string"}],
    "timeout_handling_gaps": ["string"],
    "overall_assessment": "string"
  },
  "observability_readiness": {
    "gaps": ["string"],
    "recommended_logging_points": ["string"],
    "overall_assessment": "string"
  }
}

To adapt this template, replace the placeholders with your concrete design details. For [SAGA_STEPS], provide a structured list of steps, each with its action and its compensating action. For example: Step 1: ReserveInventory() / Compensation: ReleaseInventory(). The [CRITICALITY_LEVEL] field should be a value like low, medium, high, or critical to calibrate the review's intensity. After running the prompt, you must validate the output JSON against the provided schema. Any deviation, such as a missing key or an invalid enum value, should trigger a retry or a repair prompt. For high-criticality sagas, the output of this review should be treated as a draft requiring human architect approval before being used to generate implementation code.

IMPLEMENTATION TABLE

Prompt Variables

Required and optional inputs for the Saga Orchestration Flow Design Prompt. Validate these before calling the model to prevent incomplete or unsafe saga designs.

PlaceholderPurposeExampleValidation Notes

[SAGA_NAME]

Identifies the business transaction being orchestrated

OrderFulfillmentSaga

Must be a non-empty string with no special characters except underscores. Reject if null or whitespace-only.

[PARTICIPANT_SERVICES]

List of services involved in the saga with their responsibilities

['OrderService', 'PaymentService', 'InventoryService', 'ShippingService']

Must be a non-empty array of strings. Each service name must be unique. Reject if fewer than 2 services.

[SAGA_STEPS]

Ordered sequence of local transactions with compensation pairs

[{step: 'reserveInventory', compensates: 'releaseInventory'}, {step: 'processPayment', compensates: 'refundPayment'}]

Must be a non-empty array of objects with 'step' and 'compensates' keys. Every step except the last must have a defined compensation. Reject if any compensation references a non-existent step.

[FAILURE_MODES]

Known failure scenarios to test against the saga design

['Payment timeout', 'Inventory reservation conflict', 'Shipping service unavailable']

Must be an array of strings. Can be empty if unknown. Each entry should describe a concrete failure, not a category.

[TIMEOUT_CONFIG]

Per-step timeout thresholds and global saga timeout

{stepTimeoutMs: 30000, globalTimeoutMs: 300000}

Must be an object with numeric 'stepTimeoutMs' and 'globalTimeoutMs' fields. Both must be positive integers. Reject if globalTimeoutMs is less than stepTimeoutMs.

[IDEMPOTENCY_REQUIREMENTS]

Which steps must be idempotent and the idempotency key strategy

{steps: ['processPayment'], keyStrategy: 'idempotencyKey header'}

Must be an object with 'steps' array and 'keyStrategy' string. Reject if a step marked idempotent has no key strategy defined.

[STATE_PERSISTENCE]

How saga state is persisted and queried during execution

{store: 'DynamoDB', schema: 'sagaId, status, currentStep, payload'}

Must be an object with 'store' and 'schema' strings. Reject if store is specified but schema is empty.

[OBSERVABILITY_REQUIREMENTS]

Tracing, logging, and alerting expectations for the saga

{tracing: 'OpenTelemetry', alertOn: ['stepFailure', 'timeoutExceeded']}

Must be an object. Can be empty if observability is out of scope. Validate that alertOn entries reference known failure signals.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the Saga Orchestration Flow Design Prompt into a design review application or CI/CD workflow.

This prompt is designed to be called programmatically as part of an architecture review pipeline, not as a one-off chat interaction. The core integration pattern is: collect the saga specification (steps, compensations, timeouts, state), assemble the prompt with the template placeholders filled, call a capable reasoning model, validate the structured output, and surface findings to a human reviewer or design review system. The prompt expects a detailed saga design as input, so your application must either accept a structured specification (YAML, JSON, or a design document) or guide the user to provide one before invocation.

Validation and retry logic is critical because the output schema includes enumerated severity levels (BLOCKER, WARNING, INFO) and structured finding objects. Implement a JSON schema validator on the model response. If the output fails schema validation, retry once with a repair prompt that includes the validation error and the original input. If the second attempt also fails, log the failure and escalate to a human reviewer with the raw output attached. For high-risk sagas (e.g., payment processing, inventory allocation), require explicit human approval on all BLOCKER findings before the design is accepted. Log every invocation with the input hash, model version, output, and reviewer decision for auditability.

Model selection matters: use a model with strong reasoning capabilities (GPT-4o, Claude 3.5 Sonnet, or equivalent) because the task requires multi-step causal reasoning about failure propagation and compensation chains. Avoid smaller or faster models that may miss subtle state corruption scenarios. If you are reviewing many sagas in a CI pipeline, consider batching non-critical reviews during off-peak hours and reserving synchronous execution for high-severity design changes. Tool use is not required for this prompt, but you may extend the harness to fetch related ADRs, incident reports, or existing saga definitions from a knowledge base to ground the review in organizational context. If you do, inject that context into the [CONTEXT] placeholder and cite sources in the output.

Next steps: After integrating this prompt, build a dashboard that tracks finding resolution over time. Sagas with repeated BLOCKER findings across revisions indicate a design process problem, not just a single bad design. Avoid the temptation to auto-apply fixes based on model suggestions—compensation logic changes must be reviewed by an engineer who understands the business invariants. The prompt identifies gaps; humans decide how to close them.

IMPLEMENTATION TABLE

Expected Output Contract

Fields, types, and validation rules for the saga orchestration design review output. Use this contract to parse, validate, and integrate the model response into downstream tooling or review queues.

Field or ElementType or FormatRequiredValidation Rule

saga_name

string

Must match pattern ^[a-z][a-z0-9-]+$. Non-empty. Max 128 characters.

steps

array of objects

Array length >= 2. Each object must include step_id, action, and compensation fields.

steps[].step_id

string

Unique within the steps array. Must match pattern ^step-[0-9]+$.

steps[].action

string

Non-empty. Must describe a single, idempotent operation. Max 500 characters.

steps[].compensation

string or null

If null, a human_review_required flag must be set to true at the saga level. Non-null values must be non-empty strings.

timeout_strategy

object

Must contain per_step_timeout_seconds (integer, > 0) and global_timeout_seconds (integer, >= sum of per_step_timeout_seconds).

failure_state_recovery

object

Must contain recovery_plan (string, non-empty) and orphaned_state_handling (string, non-empty).

human_review_required

boolean

Must be true if any step has a null compensation. Otherwise, can be false.

PRACTICAL GUARDRAILS

Common Failure Modes

Saga orchestration prompts fail in predictable ways. These cards cover the most common failure modes when generating saga designs and how to prevent them before they reach production.

01

Missing Compensation Steps

What to watch: The prompt generates forward steps but omits compensating transactions for one or more participants. This leaves the saga unable to roll back when a later step fails. Guardrail: Add a harness check that counts forward steps and compensating steps, requiring a 1:1 mapping. Include explicit instruction: 'For every forward action, define a corresponding compensating action that semantically undoes it.'

02

Orphaned State After Timeout

What to watch: The design assumes all steps complete or fail cleanly but doesn't specify what happens when a participant hangs or times out. Resources remain locked, and no recovery path exists. Guardrail: Require timeout durations and timeout handlers for every step. Add eval criteria that flags any step without a defined timeout action. Include a state cleanup table in the output schema.

03

Non-Idempotent Compensation

What to watch: Compensation steps are described in business terms but aren't designed to be safely retried. If the compensator itself fails or the network blips, replaying it could double-refund or double-cancel. Guardrail: Add an idempotency requirement to the prompt: 'Design each compensation step to be idempotent. Specify the idempotency key for each compensating action.' Validate that idempotency keys appear in the output.

04

Implicit Ordering Assumptions

What to watch: The prompt produces a linear sequence without documenting why steps must execute in that order. When a step fails, it's unclear whether parallel execution or reordering is safe. Guardrail: Require explicit ordering rationale in the output. Add instruction: 'For each step, state its preconditions and whether it can execute in parallel with other steps.' Test by asking the model to justify reordering any two adjacent steps.

05

Failure Mode Blindness

What to watch: The design covers the happy path and a single failure scenario but ignores partial failures, duplicate events, out-of-order delivery, and crash-recovery scenarios. Guardrail: Include a failure mode enumeration requirement: 'List at least five distinct failure scenarios and describe how the saga handles each one.' Validate the output contains distinct failure modes, not restatements of the same scenario.

06

Saga Boundary Drift

What to watch: The prompt expands the saga scope to include steps that shouldn't be part of the distributed transaction, creating unnecessary coupling and longer compensation chains. Guardrail: Add a boundary constraint: 'Only include steps that must participate in the atomic transaction. Mark any step that could be eventually consistent as out-of-scope with justification.' Review output for steps that could be moved to a separate process.

IMPLEMENTATION TABLE

Evaluation Rubric

Criteria for evaluating the quality of a generated saga orchestration design before approving it for implementation. Use these checks to catch missing compensation steps, orphaned state, and timeout gaps.

CriterionPass StandardFailure SignalTest Method

Compensation Completeness

Every forward step has a corresponding compensating action defined, including for steps that appear idempotent

A step is listed without a compensation entry, or compensation is described as 'none needed' without justification

Parse the output for a steps list and a compensations list; assert set equality of step IDs

Timeout Handling

Every external call or stateful operation includes a timeout value and a timeout-triggered transition to a compensation or terminal state

A step involving an external service call has no timeout specified, or timeout leads to an undefined state

Regex scan for external call patterns; assert each has an associated timeout field and a valid next state on timeout

Failure State Recovery

Every failure state has a defined recovery path: retry, compensate, or escalate; no state is a dead-end without explicit human escalation

A failure state transitions to itself with no exit condition, or transitions to a state not defined in the state machine

Build a state graph from output; assert every failure node has at least one outbound edge to a defined state

Orphaned State Prevention

No saga instance can terminate without all acquired resources being released or compensated; terminal states include resource cleanup verification

A success terminal state does not reference cleanup of all acquired resources listed in forward steps

Cross-reference resource acquisition steps with release steps in terminal state descriptions; assert no unmatched acquisitions

Idempotency Declaration

Each step declares whether it is idempotent, and non-idempotent steps include a guard or deduplication mechanism

A step that performs a non-idempotent operation (create, debit) lacks an idempotency key or guard description

Keyword scan for non-idempotent operations; assert each has an idempotency strategy field with a non-null value

Saga Rollback Order

Compensation steps execute in reverse order of forward steps; the design explicitly states this ordering constraint

Compensation order is unspecified, or compensations are listed in forward order implying incorrect execution sequence

Parse the compensation sequence; assert it is the reverse of the forward step sequence

Observability Checkpoints

The design includes explicit logging or event emission at saga start, each step boundary, compensation triggers, and saga terminal states

No mention of logging, events, or trace context propagation in the design output

Keyword search for log, event, trace, or emit; assert presence in at least saga start, step boundary, and terminal state sections

Human Escalation Path

Irrecoverable failure states include a clear human escalation trigger with context payload describing what failed and what state is held

An irrecoverable failure state has no escalation action, or escalation lacks context about held resources

Identify irrecoverable states from output; assert each includes an escalation action and a context payload description

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with lighter validation. Remove strict output schema requirements and focus on getting a readable saga design review. Replace [OUTPUT_SCHEMA] with a free-text instruction like "Provide a narrative review of the saga design." Skip the compensation completeness checker and timeout analysis sections if the design is still being sketched. Use a frontier model with default temperature.

Watch for

  • Missing compensation steps that go undetected without structured checks
  • Overly broad instructions producing vague recommendations instead of specific step critiques
  • No tracking of orphaned state or unhandled failure modes because the validation harness is absent
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.