Durable Execution

Workflows that
Never Fail.

Replace complex queues and state machines with simple code. Rivet Actors persist their execution state to disk, surviving server restarts and sleeping for months without resources.

onboarding.ts
1import { actor } from "rivetkit";
2
3export const userOnboarding = actor({
4 state: { step: 'welcome', userId: null },
5 actions: {
6 start: async (c) => {
7 // 1. Send welcome email
8 await c.email.send("welcome");
9
10 // 2. Hibernate for 3 days (0 cost)
11 await c.sleep("3d");
12
13 // 3. Wake up and check status
14 if (!c.state.hasLoggedIn) {
15 await c.email.send("nudge");
16 // Wait for human signal or timeout
17 await c.waitForSignal("login", "7d");
18 }
19
20 return "completed";
21 }
22 }
23});

The Sleep/Wake Cycle

Unlike standard cron jobs, Actors maintain their exact execution pointer and local variable state across sleeps. They don't restart from the beginning; they continue.

Start
Hibernating
Resume
Done
workflow_logs.txt
[10:00:00] INFO: Workflow started. sending_email...
[10:00:01] SLEEP: Hibernating for 3 days...
[+3d 00:00] WAKE: Context restored from disk.
[+3d 00:01] SUCCESS: User logged in. Completing.

Implicit State

Forget UPDATE users SET status = 'emailed'. Just define a variable in your code. Rivet persists the entire JS closure automatically.

Zero-Cost Waiting

When you await sleep('1y'), the Actor serializes to disk. You pay absolutely nothing for compute while it waits.

Reliability Guarantees

If the server crashes or deploys during a sleep, the Actor wakes up on a healthy node as if nothing happened.

Primitive for Reliability

Building blocks for systems that must finish what they start.

Durable Timers

Schedule code to run in the future using natural language. '2 days', 'next friday', or specific ISO dates.

Human-in-the-Loop

Pause execution until an external signal is received. Perfect for approval flows or 2FA verifications.

Scheduled Jobs (Cron)

Actors can be self-waking. Create a singleton actor that wakes up every hour to perform maintenance tasks.

Retries & Backoff

Wrap flaky API calls in robust retry logic. If the process crashes, it resumes exactly where it failed.

Sub-Workflows

Spawn child actors to handle parallel tasks. The parent actor waits for results, aggregating data cleanly.

State Inspection

Debug running workflows by inspecting their memory state in real-time via the dashboard or REPL.

Case Study

Payment Dunning

Recover failed payments with a stateful actor that manages the entire lifecycle of the retry process.

  • Trigger: Stripe webhook spawns a DunningActor
  • Logic: Wait 3 days, email user, retry charge
  • End: If success, kill actor. If fail after 3 tries, cancel sub.
Invoice #INV-2049
Status: Retrying (Attempt 2/3)
Pending
TodayNext Retry: 2d
Card declined. Email sent to [email protected]. Sleeping...

Connects with

Stripe
Resend
Twilio
Slack
Linear
Postgres
Discord

Sleep well at night.

Trust your critical background processes to a runtime built for durability.