</>

Retries & Timeouts

Intermediate

How Temporal makes flaky work reliable — retry policies, the four activity timeouts, and idempotency.

conceptsretriestimeoutsreliability

This is where durable execution pays off: you describe policy, and Temporal enforces it across failures and restarts — no hand-written retry loops or cron reconcilers.

Retry policies

Activities retry automatically by default. You tune a RetryPolicy:

RetryPolicy(initial=1s, backoff=2.0, max_interval=30s, max_attempts=5)
attempt 1 → wait 1s → 2 → wait 2s → 3 → wait 4s → 4 → wait 8s → 5 → fail

Workflows can also have retry policies, but retries are most commonly an activity concern.

The four activity timeouts

Distinguish queuing from running:

TimeoutCoversUse it for
schedule-to-starttime waiting in the queue before a worker picks it updetecting under-provisioned workers
start-to-closea single execution attemptthe expected runtime of one try (set this!)
schedule-to-closetotal across all attempts incl. waitsan overall deadline
heartbeatmax gap between heartbeatslong activities — detect a stuck/dead worker fast

Long-running activities should heartbeat so Temporal can fail and retry them promptly if the worker dies, instead of waiting out a long start-to-close.

Idempotency is your job

Temporal guarantees an activity runs at least once, not exactly once — a retry can happen after the side effect partially succeeded. So activities that mutate the world should be idempotent: pass an idempotency key, upsert instead of insert, check-before-charge. Temporal handles when to retry; you ensure a retry is safe.

Next: reacting to the outside world mid-flight — Signals & Queries (see outline).

Mark your progress with this note: