Skip to main content

Scheduling & Timers

The Restate SDK includes durable timers. You can use these to let handlers sleep for a specified time, or to schedule a handler to be called at a later time. These timers are resilient to failures and restarts. Restate stores and keeps track of the timers and triggers them on time, even across failures and restarts.

Scheduling Async Tasks

To schedule a handler to be called at a later time, have a look at the documentation on delayed calls.

Durable sleep

To sleep in a Restate application for ten seconds, do the following:

await ctx.sleep(10_000);

Cost savings on FaaS

Restate suspends the handler while it is sleeping, to free up resources. This is beneficial for AWS Lambda deployments, since you don't pay for the time the handler is sleeping.

Sleeping in Virtual Objects

Virtual Objects only process a single invocation at a time, so the Virtual Object will be blocked while sleeping.

Clock synchronization Restate Server vs. SDK

The Restate SDK calculates the wake-up time based on the delay you specify. The Restate Server then uses this calculated time to wake up the handler. If the Restate Server and the SDK have different system clocks, the sleep duration might not be accurate. So make sure that the system clock of the Restate Server and the SDK have the same timezone and are synchronized.