step.sleep() pauses a workflow for any duration (seconds to months) in a
durable way: the resume time is stored in the database, and the worker
slot is freed for other work. When the sleep finishes, a worker picks the
workflow back up and continues from where it left off.
This is different from setTimeout or a regular await sleep(). Those tie up
a running process and are lost if the server restarts. With step.sleep(), you
can have thousands of sleeping workflows without using any compute.
Basic Usage
How Sleep Works
When a workflow encountersstep.sleep():
- A step attempt is created with the resume time
- The workflow is durably parked in
runningwithworkerId = nullandavailableAtset to the resume time - The worker releases the workflow (frees the slot)
- When the sleep duration elapses, the workflow becomes available again
- A worker claims it and resumes from after the sleep
Duration Formats
The duration argument accepts a number followed by a unit:
Examples:
Sleep Names
Likestep.run(), each sleep needs a unique name within the workflow:
Common Patterns
Scheduled Follow-ups
Trial Expiration
Rate Limiting
When to Use Sleep
Usestep.sleep() for:
- Scheduled follow-ups (emails, notifications)
- Trial periods and expiration workflows
- Rate limiting between API calls
- Retry backoff delays
- Any pause longer than a few seconds