长时业务流程编排架构设计
根据业务步骤与等待条件选择编排方案,输出流程图、重试补偿策略及版本运维设计。
完整提示词
<context>
Processes that last minutes to months (onboarding with document checks, order fulfilment, subscription dunning, approval chains) are usually built as a status column, a few queue consumers and cron jobs that scan for rows in a state. That works until steps get lost between them, timers drift, nobody can tell where a given order is stuck, and changing the flow breaks instances already in progress. Durable workflow engines (Temporal, AWS Step Functions, Azure Durable Functions, Camunda and similar) persist the progress of each instance, so code can wait for days, retry activities with policies and resume after crashes. They add their own constraints: workflow code must be deterministic (no direct clock, random or I/O calls outside activities), activities must be idempotent because they can be retried, and changing a running workflow's definition needs explicit versioning. A state machine in your own database with an outbox and a scheduler is a valid choice for simple flows; the decision depends on the number of steps, waits, branches and how much visibility is needed.
</context>
<task>
<process>
{{process}}
</process>
{{#environment}}
<environment>
{{environment}}
</environment>
{{/environment}}
{{#problems}}
<problems>
{{problems}}
</problems>
{{/problems}}
1. If a repository is available, read how the process is implemented today (status fields, consumers, scheduled jobs) and say what you read.
2. Choose the approach: a durable workflow engine (name the realistic options for this environment), a database state machine with outbox and scheduler, or a managed state-machine service, from the number of steps, length of waits, branching, volume, need for visibility and the team's capacity to run another system.
3. Model the process: states and transitions or workflow steps, inputs and outputs, and one instance identifier that ties everything together. Draw it.
4. Define steps and activities: the external call each makes, timeout, retry policy, idempotency key, and which are safe to retry.
5. Define timers and human steps: deadlines and reminders, waiting for signals such as a payment or an approval, escalation when nobody acts, and cancellation by the user.
6. Define failures and compensation: what happens when a step fails permanently, which earlier steps must be undone, and when a person is alerted to fix an instance by hand.
7. Define versioning and operations: how definition changes apply to in-flight instances, how to find and inspect stuck instances, metrics and alerts, and data retention for completed instances.
</task>
<constraints>
- Do not put non-deterministic calls (current time, random values, network or database access) directly in workflow code for engines that replay; keep them in activities.
- Every activity that can be retried must be idempotent or protected by an idempotency key.
- Do not recommend adding a workflow engine for a two-step process without saying what it costs to run.
- Do not invent engine limits or prices; say how to check.
{{> output/uncertainty}}
</constraints>
<output_format>
## Approach
Choice and reason in at most 6 lines.
## Process model
Mermaid state or flow diagram, then a short description.
## Steps and activities
Table: step, external call, timeout, retry policy, idempotency.
## Timers and human steps
## Failures and compensation
## Versioning and operations
## Open questions
Numbered.
</output_format>可替换内容
- {{process}}
- {{#environment}}
- {{environment}}
- {{/environment}}
- {{#problems}}
- {{problems}}
- {{/problems}}
- {{> output/uncertainty}}
分类与标签
编程开发、工作流编排、状态机设计、幂等重试、故障补偿、架构设计