Opening a business account, settling an insurance claim or onboarding a supplier looks like one process to the customer, yet each takes days and touches several systems while waiting on at least one person. No database transaction lasts that long and no server process should be expected to stay up that long, so something else has to hold the process together.
In many organizations that something has grown by accident, typically as a status column, some scheduled jobs that each look for rows in a particular state, a queue or two and an analyst who knows which cases get stuck and how to push them along. It works until a step fails halfway, after which it is very hard to say with confidence what has happened to a given case.
A long-running workflow is a process whose state has to outlive any single request, process or deployment, because it spans several systems and waits on events or people. We think such workflows deserve explicit engineering, with the state, retry rules, timeouts and undo path written down in one place and executed by something built for the purpose.
In brief
- A workflow that spans days needs its state stored durably after every step, so that a crash or deployment resumes the work where it stopped instead of restarting or losing it.
- Retries are safe only when the step being retried is idempotent, so every activity that changes another system has to tolerate being run more than once.
- Each wait in a workflow needs a timeout and a defined action for when it expires, because a workflow that waits forever looks exactly like one that has been lost.
- Work that spans several systems cannot be rolled back as one transaction, so each step that changes something needs a compensating action that reverses its business effect.
- Workflows in flight will outlast the code that started them, so changes to a workflow definition have to be versioned with running instances in mind.
Why the request-and-cron approach breaks
An implicit workflow spreads its logic around, with the order of steps known only to the people who wrote the jobs, the state in a status column several jobs update, and failure handling written down nowhere.
Specific problems follow.
- Dual writes leave records wrong. A job sets the status to "account created" and then calls the core system, or the reverse, and a crash in between leaves the record disagreeing with reality.
- Cases stall without anyone noticing. A case in a status that no job is looking for sits untouched, and because nothing has failed, nothing raises an alert.
- Undoing work is a manual job. When step four fails after steps one to three have succeeded, someone has to reverse those three by hand, usually under pressure.
Choreography with events, where each service reacts to the previous one's event, removes the cron jobs but leaves the process defined and visible nowhere. That trade-off is examined in event-driven architecture: what it gives you and what it costs.
Durable state: the workflow must survive the process
The central idea is that an engine built for the purpose records the workflow's progress durably after each step, so when the worker running an instance dies, another continues from the last recorded point.
Engines take two broad approaches. State-machine engines such as AWS Step Functions store the current state and its data from states and transitions you declare in a definition language, and BPMN engines such as Camunda do the same from a process model business analysts can read. Durable execution engines such as Temporal and Azure Durable Functions instead let you write the workflow as ordinary code, recording every completed step in an event history and, after a failure, rebuilding the workflow's state by re-running the code against that history.
Replay imposes a rule worth understanding even if you never use such an engine, which is that workflow code has to be deterministic. It must make the same decisions each time it is re-run, so it cannot read the clock or a random number generator, nor call an external system directly, and anything non-deterministic goes in an activity, a separately executed step whose result is recorded once and then reused on replay.
The pseudo-code below sketches this for opening an account.
def open_business_account(application):
comp = [] # compensations, newest last
try:
customer = activity(create_customer, application,
retry=backoff(max_attempts=5))
comp.append(lambda: activity(deactivate_customer, customer.id))
activity(request_kyc_check, customer.id)
kyc = wait_for_signal("kyc_result", timeout=days(5))
if kyc is TIMEOUT:
kyc = human_task("kyc_review", customer.id, timeout=days(2))
if kyc is TIMEOUT or kyc.rejected:
raise Declined("KYC not passed")
account = activity(create_account, customer.id,
idempotency_key=application.id)
comp.append(lambda: activity(close_account, account.id))
activity(order_card, account.id, idempotency_key=application.id)
activity(send_welcome_pack, customer.id)
return account
except Exception:
for undo in reversed(comp):
undo() # each retried until it succeeds
activity(notify_applicant_declined, application.id)
raise
Retries and waits
Retries: bounded, spaced and safe to repeat
Most failures are transient (a timeout, a rate limit or a dependency restarting), and retrying handles them provided three conditions hold.
The activity has to be idempotent. An activity that timed out may in fact have succeeded, and retrying it must not create a second account or order a second card. Pass a key derived from the workflow instance and step, as the example does, so the receiving system can deduplicate, using the mechanics covered in idempotency: the property that stops integrations doing things twice.
Retries need to back off. Retrying at once adds load to a struggling system, so use exponential backoff, where each wait is longer than the last, with jitter, a random variation in the wait that keeps many instances from retrying at the same instant.
Retries need an end. Set a maximum number of attempts or a total time, and classify errors, since a timeout is worth retrying while a validation error is not and retrying a business rejection is a bug. Once retries are exhausted, the instance should move into a visible failed or needs-attention state, where it can neither disappear nor loop indefinitely.
Timeouts: every wait has an end
A workflow waits either for an activity to finish or for an external event such as a callback or a person's decision, and both need a deadline.
For external events the design should settle in advance what happens when the deadline passes, whether a reminder, escalation, default path or cancellation. In the example, a KYC provider that gives no answer within five days triggers a manual review, and a review left uncompleted ends in a decline with a notification. Timers in a workflow engine are durable, so a five-day wait holds across restarts and deployments.
Compensation: undoing what cannot be rolled back
Work that crosses several systems has no shared transaction to roll back. The established answer is the saga, a sequence of local transactions in which each has a compensating action that reverses its business effect, with those compensations run in reverse order if a later step fails.
Three things here are easy to get wrong.
Compensation differs from a rollback. The earlier step was committed and may already have been seen, and closing an account differs from never opening it, since a record remains along with perhaps a statement or regulatory report, so design the compensation as a real business operation with its own rules.
Some steps cannot be compensated at all. A sent letter cannot be unsent and a released payment may be unrecoverable, so order the workflow with irreversible steps last, after everything that might fail. In the example, the welcome pack goes out only after both the account and the card exist.
Compensations can fail as well. They must be idempotent and retried until they succeed, and one that cannot succeed sends the instance to a person with the full history, because a silently abandoned compensation leaves exactly the half-finished state the saga was meant to prevent.
People are a wait too
A human task is an activity of long and unpredictable duration, so the workflow creates the task with the data the person needs and waits for a completion signal under a deadline with an escalation.
Where an AI system proposes and a person approves, the design questions are covered in designing human approval into agent systems.
Account opening at a regional bank
Consider a regional bank that opens business accounts through a web form, behind which scheduled jobs move applications along a status column. The jobs create the customer in the core system and request identity and business checks from an external provider, then create the account, order a card and send the welcome pack.
One week, after a certificate change, the provider's callback endpoint is misconfigured and callbacks fail for two days. Applications sit in "awaiting check" with no alert, since nothing has errored on the bank's side. Separately, a batch of applications fails at card ordering on a data format issue, leaving those customers with an account but no card or explanation, while the job that would retry them looks only for a status these rows no longer have, so operations staff rebuild the picture from logs and fix each case by hand.
An explicit workflow changes how the process fails.
- Each application is one workflow instance with a full history, so its status is a lookup rather than an investigation.
- The wait for the provider has a five-day timeout that routes to manual review, and a dashboard shows instances by state and age, so two days of missing callbacks show up as a growing count in one state.
- Card ordering retries with backoff and then stops in a needs-attention state with the error recorded, and once the format is fixed, operations resume those instances from that step.
- If the check fails after the customer record exists, the compensation deactivates it and notifies the applicant without anyone having to remember.
The bank would track instances per state older than the expected duration and the count needing manual intervention, along with the time it takes to answer a status query.
Operating and changing workflows
Two operational facts often catch teams out.
In-flight instances outlive deployments. Instances part way through when the definition changes either continue on the old definition or must be migrated. With replay-based engines, a changed code path can make an old history impossible to replay unless the change is guarded by the engine's versioning mechanism, so each change needs a decision on whether old instances finish on the old version or are migrated deliberately.
A workflow engine is a production system. Like any other part of cloud operations, it needs monitoring and capacity planning as well as backup and an on-call owner, and the most useful signals are instance counts by state, the age of the oldest instance per state, retry rates per activity and compensation failures.
The approach has a real limit, since an orchestrator is one more moving part with its own learning curve, and a two-step process with no waits is better served by a queue with an idempotent consumer.
Questions to ask about your current workflows
- For your three most important multi-day processes, where is the sequence of steps defined? If the answer is "across several jobs", what you have is an implicit workflow.
- Can you show the state and history of one specific case in less than a minute?
- For each step that calls another system, what happens if it runs twice?
- For each wait, what is the timeout and what happens when it fires?
- For each step that changes something, what is the compensation, who owns it, and has it ever been run?
- Which steps are irreversible, and do they come last?
- What happens to cases in flight when you deploy a change?
If these have no ready answers, start by making one process explicit. That is the substance of workflow orchestration, and it rests on the foundations shared with systems integration and business process automation, which are known state and safe retries with a planned way back.



