Learning pathsPricingChecking sign-in…
GUIDED PRACTICE

Temporal

Temporal is a workflow platform for durable application processes that must wait, retry, and resume across worker failure.

What, why, when and how

What is it?

Temporal provides durable workflow execution using recorded event history and workers that execute workflow and activity code.

Why is it needed?

Business processes need to survive worker restarts, timers, retries and long waits without losing their place.

When should I use it?

Use it for durable orchestration with several steps, callbacks or compensation paths.

When should I choose something else?

A single database transaction or basic queue consumer may be sufficient for simpler work. Workflow history does not make external activity effects automatically exactly once.

How do I use it?

Keep workflow decisions deterministic, perform external effects in activities, configure timeouts and retries, use stable activity identities and plan compatible code changes.

Can you show a concrete example?

A payment activity succeeds at the provider but its worker dies before reporting completion. A retry uses the same provider operation identity or reconciles its status so workflow recovery does not produce a second charge.

Activity charges using operation ID p7; Worker dies before recording activity completion; Retry or reconcile p7; do not invent a new ID
Temporal: one concrete example
Read the diagram

Activity charges using operation ID p7; Worker dies before recording activity completion; Retry or reconcile p7; do not invent a new ID

Open original
Temporal: worked example
Activity charges using operation ID p7; Worker dies before recording activity completion; Retry or reconcile p7; do not invent a new ID

Temporal: one concrete example

Follow the detailed diagrams below to trace the additional state changes and failure cases behind these answers.

Temporal is a workflow platform for durable application processes that must wait, retry, and resume across worker failure. Use it when process state and time span matter more than a single request handler. It does not make external side effects exactly once; activities and their destinations still need idempotency and reconciliation.

Reconstruct decisions from event history

Suppose workflow w7 schedules reserve activity a1 and then waits for payment. Its history records scheduling and a1's completion. A replacement worker replays workflow code against this history, receiving the recorded result rather than issuing a fresh reserve command for that same recorded decision.

Contract / pseudocode
history: WorkflowStarted(w7)
         ActivityScheduled(a1)
         ActivityCompleted(a1,H1)
         TimerStarted(expiry)
replay: use H1; restore wait; do not invent reserve a2
history: WorkflowStarted(w7);          ActivityScheduled(a1);          ActivityCompleted(a1,H1);          TimerStarted(expiry); replay: use H1; restore wait; do not invent reserve a2
Reconstruct decisions from event history
Read the diagram

history: WorkflowStarted(w7); ActivityScheduled(a1); ActivityCompleted(a1,H1); TimerStarted(expiry); replay: use H1; restore wait; do not invent reserve a2

Open original
Reconstruct decisions from event history
history: WorkflowStarted(w7);          ActivityScheduled(a1);          ActivityCompleted(a1,H1);          TimerStarted(expiry); replay: use H1; restore wait; do not invent reserve a2

Reconstruct decisions from event history

Workflow code must reproduce compatible commands on replay; random values, current wall clock and ordinary network calls cannot be inserted as uncontrolled workflow decisions. Use supported deterministic APIs or activities. A workflow waiting on a durable timer is not one sleeping application process per order. Signals/updates carry correlated external input under declared validation and ordering.

Activities execute outside workflow history's decision boundary. If payment P1 succeeds but its completion was not recorded, an activity retry may run. Reuse P1 or reconcile it; recorded workflow replay does not automatically dedupe provider effects. Workers poll task queues, and queue/worker capacity can bottleneck execution independently of the orchestration service.

Version code so running histories remain compatible. Bound history size, use external immutable payload references, and continue into a new run where appropriate without dropping the business identity. Test deployment against a waiting old workflow and a replay fixture.

Show answer and explanation

Answer: A recorded completed activity can return its stored result on workflow replay. A possibly completed external call whose result never reached history remains uncertain and requires its own idempotency/reconciliation policy.

Step-by-step reasoning

1. 1 · Frame

Model the business workflow first: identity, state transitions, signals, timers, cancellation, and terminal conditions. A workflow execution replays its event history, so workflow code must obey deterministic execution rules. Put network calls, database access, and other side effects in activities. Keep workflow histories bounded through appropriate continuation strategies for very long or high-event processes.

2. 2 · Model

Start workflows with stable IDs so duplicate start requests resolve intentionally. Activities have task queues, timeouts, and retry policies. Choose activity idempotency keys derived from workflow and step identity. Signals deliver external events into workflow state; validate their identity and expected sequence. Child workflows can isolate repeated sub-processes, but their state and limits remain operational concerns.

3. 3 · Scale

Workers poll task queues, so scale them according to activity duration and external capacity. Temporal service stores execution histories; operators need visibility into backlog, retries, task schedules, and stuck workflows. Version workflow behavior as deployed code evolves because replay may encounter histories created by older logic. Define cancellation and compensation as product behavior, not just a worker shutdown.

4. 4 · Recover

A workflow activity charges a provider and times out after the charge succeeds but before the result is recorded. Retry with the same provider identity or query status. Workflow history records orchestration progress, not every fact inside an external system. Reconciliation remains necessary for missing callbacks, provider state drift, and manual repair.

Contracts and state

The following sketch makes the decision boundary concrete. Field names and capacity assumptions are illustrative; adapt them to the stated product contract.

Contract / pseudocode
Workflow(id, type, input_version, state history)
Activity(step_id, attempt, timeout, retry policy)
ExternalEffect key = workflow_id + step_id
Signal(event_id, expected_transition)
History: deterministic decisions; side effects happen in activities

Worked example

An order workflow reserves inventory, waits up to 15 minutes for payment, then confirms or releases. The process can remain durable while no worker is active during the wait. When payment signal arrives, the workflow validates its identity and advances. If the worker restarts, it replays recorded decisions and schedules only the activity still required.

Failure walkthrough

A deployment changes workflow code so replaying a prior history follows a different command sequence. That can fail determinism checks. Introduce compatible workflow versioning and migration strategy, then test old histories before rolling out. Do not force-reset live executions without understanding business state or external effects already completed.

Workflow waits for payment → Timer is persisted → Worker deployment restarts → History replays deterministically → Payment signal resumes next step
Temporal · scenario walkthrough
Read the diagram

Workflow waits for payment → Timer is persisted → Worker deployment restarts → History replays deterministically → Payment signal resumes next step

Open original
Temporal · scenario walkthrough
Workflow waits for payment → Timer is persisted → Worker deployment restarts → History replays deterministically → Payment signal resumes next step

Temporal · scenario walkthrough

Decisions and trade-offs

Use Temporal whenSimpler alternativeTrade-off
Multi-step durable processOne queue + job rowWorkflow history and versioning
Long timers / signalsScheduled task tableService dependency and operational model
Activity retriesApplication retry loopDuplicate external effect risk remains
Human waitPolling a status fieldLong-lived execution and retention

Check your understanding

An activity times out after an external charge might have completed. What should the retry do?

Show answer and explanation

Answer: Use an idempotent operation identity stable across activity attempts, or query the provider by the original reference before issuing a new charge. The workflow can durably retry orchestration, but it cannot infer the external result from its timeout alone.

Primary documentation

Read the first-party engineering account or official technical reference. Company engineering posts describe the scope and date of that publication; the interview reconstruction and scenarios here are original teaching examples.

Continue the connection

Study Managing Long Running Tasks and explain which guarantee from this lesson carries into that topic.

Distinguish replayed workflow code from retried activities

A durable workflow records its history and reconstructs logical state by replay. Workflow code must obey the platform’s deterministic execution rules; arbitrary network calls, unrecorded randomness or uncontrolled wall-clock reads can make replay diverge. Activities perform external work and have their own retry and timeout behavior.

If a payment activity times out, the workflow must not assume the provider did nothing. Give the activity a stable business operation key and reconcile uncertain outcomes. Activity retries can rerun code after partial completion. Durable orchestration removes much scheduling and state bookkeeping, but it does not remove the need for idempotent side effects.

Long histories need a lifecycle strategy such as continuing into a new run while preserving necessary state. Code changes must remain compatible with in-flight histories using supported versioning techniques. Separate activity queue delay, execution time, heartbeat progress and total workflow deadline when configuring limits.

A decision worksheet for Temporal: read the mechanism and its guarantee together.
A decision worksheet for Temporal: read the mechanism and its guarantee together.
Read the diagram

Use Temporal when / Simpler alternative / Trade-off; Multi-step durable process / One queue + job row / Workflow history and versioning; Long timers / signals / Scheduled task table / Service dependency and operational model; Activity retries / Application retry loop / Duplicate external effect risk remains; Human wait / Polling a status field / Long-lived execution and retention

Open original
Temporal choices for this workload
A decision worksheet for Temporal: read the mechanism and its guarantee together.

A decision worksheet for Temporal: read the mechanism and its guarantee together.

Operational sketch

Contract / pseudocode
workflow: reserve -> authorize -> confirm
activity input includes stable payment_operation_id
on uncertainty: query provider before new charge
on business failure: schedule retryable compensation
record workflow version and operational deadline

A tempting mistake

A workflow retry that creates a new business key can charge again. The identity of the business operation should not be regenerated merely because a worker restarted.

Transfer exercise

Why must workflow code avoid directly reading an external API during replay?

Show answer and explanation

Answer: The response can change and replay must reconstruct recorded decisions consistently. External effects belong in activities or another supported recorded mechanism.

Shared foundation: Outbox, Inbox, Sagas and Reconciliation

Outbox, Inbox, Sagas and Reconciliation: Recover publication gaps, duplicate deliveries and uncertain compensation using durable business state. Work its failure history before extending this design.

Shared foundation: Schema, API and Event Evolution

Schema, API and Event Evolution: Test mixed-version contracts, semantic meaning, retained replay and identity-preserving rollout or rollback. Work its failure history before extending this design.

10:00Self-guided practice timer
The timer resets when you leave this page. Save your design separately.
Your challenge

An activity times out after an external charge might have completed. What should the retry do?

Your design draft

Clarify assumptions, explain your approach, and test the difficult cases. Save your draft, then compare it with the study notes.

Read study notes

Self-review checklist

Self-guided practice. Automated AI feedback and code execution are not connected.