Sign In
Hosting Providers

Cloudflare Workers

Deploy Rivet Actors to Cloudflare Workers with Durable Objects for global edge computing with persistent state.

Feature Support

FeatureSupported
Horizontal scalingYes
WebSocketsYes
SSEYes
EdgeYes
SchedulingYes

Setup

Install packages

Install the Cloudflare Workers driver:

Command Line
npm install @rivetkit/cloudflare-workers

Configure the driver

Update your server code to support Cloudflare Workers:

server.ts
import { createServer } from "@rivetkit/cloudflare-workers";
import { Hono } from "hono";
import { registry } from "./registry";

const { client, createHandler } = createServer(registry);

// Setup router
const app = new Hono();

// Example API endpoint
app.post("/increment/:name", async (c) => {
  const name = c.req.param("name");

  // Get or create actor and call action
  const counter = client.counter.getOrCreate(name);
  const newCount = await counter.increment(1);

  return c.json({ count: newCount });
});

const { handler, ActorHandler } = createHandler(app);

export { handler as default, ActorHandler };

Configure Wrangler

Update your wrangler.json configuration to support ACTOR_DO and ACTOR_KV bindings:

wrangler.json
{
  "name": "my-rivetkit-app",
  "main": "src/index.ts",
  "compatibility_date": "2025-01-20",
  "compatibility_flags": ["nodejs_compat"],
  "migrations": [
    {
      "tag": "v1",
      "new_classes": ["ActorHandler"]
    }
  ],
  "durable_objects": {
    "bindings": [
      {
        "name": "ACTOR_DO",
        "class_name": "ActorHandler"
      }
    ]
  },
  "kv_namespaces": [
    {
      "binding": "ACTOR_KV",
      "id": "your_namespace_id"
    }
  ]
}

Configuration Requirements:

  • ACTOR_DO - Durable Object binding for actor persistence
  • ACTOR_KV - KV namespace binding for metadata storage
  • nodejs_compat - Required compatibility flag
  • Migration with ActorHandler class definition

Deploy

Deploy your application to Cloudflare Workers:

Command Line
wrangler deploy

Your actors will now run on Cloudflare's global edge network with persistent state backed by Durable Objects.

Examples

Suggest changes to this page