A durable timer is a wait inside a workflow whose deadline is stored persistently by the orchestration engine rather than held in process memory, so the wait survives crashes, restarts and redeployments and resumes the workflow when the time arrives. In the reliability of automation, durable timers make it safe to write logic such as “wait 30 days, then send a renewal notice” directly in workflow code without a cron job or a polling loop.
Durable timers are a core primitive of durable execution platforms such as Temporal, Cadence, Azure Durable Functions, AWS Step Functions and Cloudflare Workflows. While a timer is pending, the workflow consumes no worker thread, memory or compute, which is why a single cluster can hold millions of sleeping workflows.
How a durable timer is recorded and fired
A durable timer works by turning a sleep call into an event in the workflow history and a row in the engine’s timer store. When workflow code calls an API such as workflow.sleep() or context.CreateTimer(), the engine records a timer-started event with the absolute fire time, and the worker then releases the workflow from memory.
A timer service inside the engine scans persisted deadlines, usually from an index ordered by fire time. When a deadline passes, it appends a timer-fired event to the history and schedules a new workflow task. A worker picks up that task, rebuilds the workflow state by replaying the history, sees that the timer has fired and continues with the next line of code.
The following table summarizes the stages of a single timer.
| Stage | What the engine stores | Worker activity |
|---|---|---|
| Creation | Timer identifier and absolute fire time | Workflow code reaches the wait call |
| Pending | Entry in the persistent timer index | None; workflow is evicted from memory |
| Firing | Timer-fired event in the history | None until a task is dispatched |
| Resumption | New workflow task in the task queue | Worker replays history and continues |
| Cancellation | Timer-canceled event in the history | Code takes an alternative branch |
Because the deadline is stored as an absolute timestamp, a restart of the whole cluster does not reset the countdown. If the engine was down when the deadline passed, the timer fires as soon as the engine recovers, so the wait is guaranteed to end, though possibly late.
Durable timers versus in-memory waits and schedulers
A durable timer differs from an ordinary setTimeout or Thread.sleep in where the waiting state lives. An in-memory wait disappears with the process, while a durable timer belongs to the workflow instance and is protected by the engine’s database.
| Mechanism | Survives restart | Holds resources while waiting | Typical duration |
|---|---|---|---|
| In-memory sleep | No | Thread or event loop slot | Milliseconds to minutes |
| Delayed queue message | Yes, if the broker persists it | Broker storage only | Seconds to days, broker-dependent |
| Cron or scheduled job | Yes | Scheduler entry | Recurring, not per instance |
| Database polling | Yes | Periodic queries | Any, with polling delay |
| Durable timer | Yes | History and timer index only | Seconds to months or years |
The decisive advantage is per-instance context. A cron job must rediscover which records are due, whereas a durable timer already knows which order, customer or contract it belongs to, and the code after the wait has all local variables restored by replay.
Common patterns built on durable timers
Most reliability patterns in long-running automation combine a durable timer with an external event. The workflow waits for whichever comes first, which turns a timer into a deadline or timeout for human approval, payment confirmation or a partner callback.
| Pattern | How the timer is used | Example |
|---|---|---|
| Timeout race | Timer competes with an incoming signal | Cancel an order if unpaid after 24 hours |
| Reminder and escalation | Series of timers between notifications | Remind an approver after 2 days, escalate after 5 |
| Delayed retry | Timer between attempts of a business step | Retry a failed shipment booking after 1 hour |
| Grace period | Timer before an irreversible action | Delete an account 30 days after closure |
| Polling with sleep | Timer between status checks | Check a batch export every 10 minutes |
| Recurring loop | Timer at the end of each iteration | Monthly billing cycle per subscription |
In a timeout race, the losing branch must be handled explicitly. When the signal arrives first, good practice is to cancel the pending timer so the history stays short and no stale task is scheduled later.
Precision, determinism and engine limits
Durable timers guarantee that a workflow will not resume early, but they do not guarantee sub-second precision. Firing delay depends on the timer scan interval, task queue backlog and worker availability; in a healthy cluster it is usually well under a few seconds, while an overloaded system can add minutes.
Workflow code must obtain time only through the engine’s deterministic clock, for example workflow.now() or context.CurrentUtcDateTime. Reading the system clock directly produces a different value during replay and can cause non-determinism errors or timers computed from the wrong base time.
- Some engines historically capped a single timer and chained shorter timers internally for longer waits.
- Very long loops of timers grow the history and should be reset with a continue-as-new operation.
- Changing a timer duration in deployed code requires workflow versioning, because running instances replay the old history.
- Timer events count toward history size and billing on managed platforms.
Mistakes that weaken timer reliability
Most failures attributed to durable timers come from workflow code that breaks the replay contract or from assumptions about exact timing. The table lists frequent problems and remedies.
| Symptom | Cause | Fix |
|---|---|---|
| Replay fails after deploy | Timer duration changed without versioning | Add a version branch or patch marker |
| Timer fires at an odd hour | Local time or daylight saving not handled | Compute deadlines in UTC with explicit zones |
| Workflow never resumes | Worker for the task queue is not running | Monitor task queue backlog and worker count |
| History limit reached | Endless loop of timers in one run | Use continue-as-new at regular intervals |
| Action runs twice after timeout | Side effect not idempotent | Make downstream activities idempotent |
A durable timer only protects the wait itself. The work that follows the timer still needs idempotent activities, a sound retry policy and monitoring, because an activity can fail or run more than once after the workflow resumes.
In everyday language
A durable timer is like writing a deadline in a shared paper calendar instead of trying to remember it. If the person who wrote it goes on vacation, gets sick or changes desks, the date is still in the calendar. When the day comes, whoever is on duty sees the note and carries on.
For software, this means a process can wait for hours, weeks or months without keeping a computer busy. Nothing is forgotten when servers restart, and the waiting step picks up exactly where it left off.
Seen in the real world
An insurance company automates policy renewals with a durable execution engine. Each policy has its own workflow that sends an offer 45 days before expiry, then waits on a durable timer for either the customer’s acceptance signal or a 14-day deadline.
If the customer does not respond, a second timer sends a reminder, and a third timer escalates the case to an agent seven days before expiry. During a planned database migration the cluster was offline for two hours; timers that came due during the outage fired within minutes of recovery, and no renewal notice was lost or sent twice because the notification activities checked a message identifier before sending.
With roughly 400,000 active policies, almost all workflows sit in the pending timer state at any moment, using storage rather than compute.