Temporal Workflow: 7 Choices for Recoverable Business Processes
A Temporal workflow defines a business process in code. It tracks progress through a durable event history, a stored record of what happened. It can wait for work, timers, or outside signals. The same server does not have to stay alive throughout the wait. This helps when a process spans several services or takes hours or days. The team still needs to define safe retries and business recovery.
This guide explains Temporal durable execution through an order fulfillment example. It covers workflows, activities, duplicate effects, waiting, code changes, and operations. You will also see when a simple job queue is enough. Then you can test a focused pilot before moving critical work.
1. Choose a process with real waiting and recovery needs
Start by drawing one business process and its failure points. An order may reserve stock, collect payment, request shipment, and wait for a carrier result. Each step can fail at a different time. A basic script often has no clear record of where to resume.
Temporal can help coordinate those steps and preserve progress. It does not make the stock service or payment provider reliable by itself. Nor does it decide whether a failed order needs a refund, a retry, or staff review. Those are business rules the team must supply.
Look for workflows where lost progress creates costly manual work. Staff may search logs to discover whether a payment happened before a crash. Or several scheduled jobs may check each other’s status fields. Those are signs that durable orchestration may offer value.
However, a short task with a simple retry path may need only a queue and a worker. Compare the full cost of running another platform with the problem you face. A narrow pilot should prove that the process becomes easier to recover and support.
2. Separate workflow decisions from activities
A workflow describes the order of work and the choices between steps. An activity performs outside work, such as calling a payment API or updating another database. This separation lets the system record progress while keeping external calls out of workflow replay.
The official Temporal workflow documentation explains event history and replay. A worker can use recorded events to rebuild workflow state. It does not simply restore a frozen server’s memory or repeat every completed outside call from scratch.
For a business owner, the useful distinction is plan versus action. The workflow decides that payment comes after stock reservation. The payment activity calls the provider and returns a result. Keep the business meaning of that result clear, including uncertainty.
A card decline differs from a network timeout. One may be a final business answer, while the other may need a status check or retry. If an activity treats all failures alike, the workflow may choose the wrong next step. Durable state does not fix that rule.
Use clear state names
Choose names that staff can understand, such as awaiting payment or shipment requested. A generic processing state hides too much. If staff must act, show why the process is waiting and which action is safe.
Our guide to document workflow automation shows why ownership and waiting states matter in long tasks. The same principle applies here: durable execution preserves a process, but useful states make it supportable.
3. Make outside effects safe to retry
An activity may run again if a worker fails or its result does not reach the service. That means an outside effect can happen more than once unless the integration prevents it. Do not turn durable execution into a claim that every external action happens exactly once.
Use an idempotency key where the provider supports it. A stable order payment reference can let repeated requests refer to one intended charge. Use the same key for attempts of that business action. Also check how long the provider keeps the key and where it applies.
If the provider lacks that feature, design another safe method. You may query by a unique business reference or place a guarded record around the action. Some cases need manual review when the outcome remains unknown. State that limit rather than retry blindly.
Test a crash after the outside action succeeds but before the activity reports success. This is the case a happy path demo often misses. The next attempt should find or safely repeat the result. It must not charge twice or create a second shipment.
4. Keep workflow code safe for replay
Workflow code must behave consistently when replay follows the same recorded history. A direct network call could return a new value during replay. Reading the current system clock directly can also change a decision. Use the SDK’s supported workflow tools for time and other replay-safe operations.
The Temporal workflow definition guide explains deterministic code and places external interactions in activities. Deterministic means the workflow produces the expected sequence of commands from its recorded inputs. It does not mean the outside world never changes.
When a workflow needs a new fact, have an activity fetch it and return a clear result. Then the workflow can use that recorded result in its decisions. Keep large or sensitive payloads under review, since histories can retain inputs and outputs.
Code changes need care too. A new branch or reordered step may conflict with the history of an older running workflow. Use the supported versioning and deployment approach for your SDK and platform. Test old histories before sending a new worker build into production.
5. Model waits, deadlines, and human actions
A durable timer lets a workflow wait without keeping one worker thread asleep for days. The process can resume when the wait ends. This suits review deadlines, delayed follow-up, or a pause before checking an external result.
Human actions need a defined message path. A manager might approve an order through the app. The app then sends a signal or another supported message to the workflow. The application must verify who may send that action. Temporal is not a substitute for user authorization.
Plan races between a deadline and an approval. If the deadline wins, can a late approval reopen the process? If two users act, which decision counts? State the rule and make repeated messages safe. A durable system can preserve ambiguity just as reliably as a clear decision.
Also define cancellation. Stopping future workflow steps may not undo an outside action already in progress. A shipment request may have reached the carrier. Staff need to see whether cancellation is pending, complete, or no longer possible.
6. Walk through an order fulfillment failure
Consider an illustrative wholesaler. Its workflow reserves stock, takes payment, requests shipment, and waits for a carrier response. Each order has one stable workflow identity under the team’s chosen ID rules. A repeat submission should not create a second independent order process by accident.
First, stock reservation returns a reference and expiry. The workflow then starts payment using a stable charge key. Suppose the worker stops after the provider accepts payment. A later attempt checks or repeats the request safely under that key.
Next, shipment creation times out. The workflow does not assume the carrier rejected it. An activity checks the carrier’s status using the order reference. If the outcome stays unknown, the process moves to a visible review state. It does not create another shipment.
Suppose staff confirm that no shipment exists and cancel the order. The workflow follows the agreed recovery steps, including stock release and refund where required. These are compensating actions. They are new business actions, not a magical rollback across several remote systems.
Finally, the team tests a refund failure. The order should show refund pending with a named support path. Marking the whole process cancelled without that detail would hide a customer obligation. Durable state helps only when it reflects what still needs to happen.
7. Build an operations model before wider adoption
Choose a managed service or run the platform yourself. Compare data rules, uptime needs, staff skills, and the work to run each option. A managed service can reduce some hosting duties. Even so, your team owns the workers, activity behavior, and steps to recover the business process.
Monitor task backlogs, worker health, activity failures, and workflows stuck beyond expected times. Tie alerts to a business outcome. A failed activity that safely retries may need no alert. In contrast, a paid order waiting too long for shipment may need urgent help.
Our observability guide explains how to connect signals across a process. Use shared references so support can trace the order, payment, and shipment. Keep private payloads out of routine logs.
Protect history and control access
Review the data each workflow and activity receives. Event histories may hold business data for the configured retention period. Where it fits, pass a document ID instead of the full file. Apply suitable access controls and payload protection for the chosen deployment.
Also restrict operational actions such as starting, signaling, resetting, or terminating workflows. These can affect real business obligations. Give staff tools that explain the effect and capture an audit record. A broad admin console should not become the everyday business interface.
Before launch, run failure drills with the real test integrations. Stop a worker, delay a provider, repeat a signal, and deploy changed code against saved histories. Our guide to API mocking tools can help simulate controlled edge cases, alongside real adapter tests.
Set acceptance criteria that reflect the pain you chose to solve. Can staff locate the current step without reading raw logs? Does a retry avoid a second charge? Can an old workflow continue after deployment? These checks give a pilot more value than a successful demo order.
Keep the first scope small. Move one process with known owners and a clear recovery path, then review the support effort. Expand only when the team can explain both normal progress and awkward failures. Durable execution is most useful when it makes those failures manageable.
Give staff a recovery view tied to the business
Support should see the order and its current obligation, not just a failed task. Show whether stock is held, money has moved, and a shipment exists. Mark an unknown result as unknown. A green process badge must not hide a pending refund.
Next, define the actions staff may take from that view. They might check a provider result, retry a safe step, or send the case for review. Each action needs a clear scope and audit record. Avoid a generic restart button that can repeat every outside effect.
Test the view with a person who did not build the workflow. Give them a case where payment succeeded and shipment status is unclear. Ask what they would do next. If they need raw code or a guess, improve the states and help text.
Also check duplicate starts at the front door. A user may click twice or retry after a slow page. Choose a stable business reference and a supported workflow ID policy. Then prove that the two requests do not create two independent charges.
Finally, decide how long staff need the history for support and audit. Keep that need in balance with data limits and retention rules. A durable process should preserve enough evidence to resolve a case without keeping every private input forever.
Frequently Asked Questions
Does a Temporal workflow guarantee exactly-once payments?
No. External activities can retry. A provider may finish an action before the worker reports success. Use provider idempotency, status checks, or another proven design to prevent duplicate effects. Test the uncertain outcome case.
Can a workflow call an API directly?
External calls belong in activities so workflow replay can use recorded results. Use the SDK’s supported workflow APIs for replay-safe operations. This keeps changing outside values from altering the replay path.
When is a job queue simpler than Temporal?
A queue may suffice for a short independent task with a clear retry and status model. Consider Temporal when you need to coordinate several steps and long waits. It can help where a basic queue leaves too much state and repair work to your team.
Make one long-running process recoverable
Oxen Softwares can help map retries, waiting states, and recovery actions for a focused workflow pilot. Start with one process where lost progress causes real support work.