Sign In
Promo Image

Rivet Actors on Vercel Functions: Open-Source Alternative to Durable Objects

Rivet Actors can now run on Vercel Functions, bringing stateful, realtime workloads to Vercel's serverless platform.

Cloudflare's Durable Objects introduced a long-lived, stateful primitive in serverless apps – but they come with platform lock-in and resource constraints. Rivet Actors offer an open-source alternative, and by launching on Vercel we unlock better flexibility, control, and developer experience.

How Vercel + Rivet Compares To Durable Objects

DimensionRivet Actors on Vercel FunctionsCloudflare Durable ObjectsWhy it matters
RuntimeStandard Node.js (Vercel Functions), full support with npm packagesCustom runtime (workerd), subset of Node.js APIs, partial support with npm packagesUsing standard Node.js makes packages and frameworks "just work" and reduces vendor lock-in.
Memory / CPU per actorConfigurable up to 4 GB / 2 vCPUPer-isolate memory cap 128 MBMemory-heavy workloads are more feasible on Vercel than on Cloudflare
Regional controlConfigurable specific regionsDOs can be restricted to broad jurisdictions and accept location hints, though limited controlExplicit control helps reduce latency and meet compliance requirements
Lock-in / portabilityOpen-source actor library designed to be portable across standard runtimes/cloudsDOs run on Cloudflare's runtime and APIs, not open-source, not portableOpen source + standard runtimes provide flexibility, enables migrations, and allows for on-prem deployments

What Are Rivet Actors?

Similar to Durable Objects, Rivet Actors provide long-lived, stateful actors with storage, real-time (WebSockets/SSE), and hibernation. However, unlike Durable Objects, Rivet is open-source and portable — you can self-host or run on any platform.

  • Long-Lived, Stateful Compute: Each unit of compute is like a tiny server that remembers things between requests – no need to re-fetch data from a database or worry about timeouts. Like AWS Lambda, but with persistent memory between invocations and no timeouts.

  • Realtime, Made Simple: Update state and broadcast changes in realtime with WebSockets or SSE. No external pub/sub systems, no polling – just built-in low-latency events.

  • No Database Round Trips: State is stored on the same machine as your compute so reads and writes are ultra-fast. No database round trips, no latency spikes.

  • Sleep When Idle, No Cold Starts: Actors automatically hibernate when idle and wake up instantly on demand with zero cold start delays. Only pay for active compute time.

  • Architected For Insane Scale: Automatically scale from zero to millions of concurrent actors. Pay only for what you use with instant scaling and no cold starts.

  • No Vendor Lock-In: Open-source and fully self-hostable.

Why Run Rivet With Vercel?

Running Rivet Actors on Vercel provides many benefits:

  • Industry standard runtime: Runs on Node.js today (with Bun coming soon to Vercel Functions). No proprietary runtime, use the Node APIs and NPM packages you already know.
  • More memory & CPU: Vercel Functions let you configure memory and vCPU per function (up to 4 GB RAM, 2 vCPU cores). This enables larger PDF processing, multiplayer games, agent context, and heavier compute that would exceed typical isolate caps.
  • Scale to zero with zero cold starts: Actors scale down when idle to eliminate costs, yet wake instantly on demand with hibernation preserving state for immediate activation.
  • Regions you choose: Set regions directly to keep actors close to your primary database or within compliance boundaries.
  • Developer experience: Deploy actors alongside your Next.js app in one place, leverage Vercel's best-in-class observability, and use Rivet's built-in inspector for deep visibility into your actors.

One More Thing: WebSockets on Vercel Functions

Until today, Vercel Functions have not supported WebSockets. Rivet now enables native WebSockets with code running directly in Vercel Functions, powered by our tunneling technology. This brings the flexibility and power of traditional WebSocket servers like Socket.io to Vercel's fully serverless platform for the first time.

This unlocks use cases like:

Read more about realtime events and the raw WebSocket handler.

Quick Example: Building an AI Agent with Rivet Actors

A stateful AI chatbot with persistent memory and real-time updates:

import { actor, setup } from "rivetkit";
import { openai } from "@ai-sdk/openai";
import { generateText, tool } from "ai";
import { z } from "zod";
import { type Message, getWeather } from "../lib/utils";

// Create an actor for every agent
export const aiAgent = actor({
	// Persistent state that survives restarts
	state: {
		messages: [] as Message[],
	},

	// Actions are callable by your frontend or backend
	actions: {
		getMessages: (c) => c.state.messages,

		sendMessage: async (c, userMessage: string) => {
			const userMsg: Message = {
				role: "user",
				content: userMessage,
				timestamp: Date.now(),
			};

			// State changes are automatically persisted
			c.state.messages.push(userMsg);

			const { text } = await generateText({
				model: openai("gpt-4-turbo"),
				prompt: userMessage,
				messages: c.state.messages,
				tools: {
					weather: tool({
						description: "Get the weather in a location",
						inputSchema: z.object({
							location: z
								.string()
								.describe("The location to get the weather for"),
						}),
						execute: async ({ location }) => {
							return await getWeather(location);
						},
					}),
				},
			});

			const assistantMsg: Message = {
				role: "assistant",
				content: text,
				timestamp: Date.now(),
			};
			c.state.messages.push(assistantMsg);

			// Send realtime events to all connected clients
			c.broadcast("messageReceived", assistantMsg);

			return assistantMsg;
		},
	},
});

export const registry = setup({
	use: { aiAgent },
});

Getting Started on Vercel

  1. Sign in to Rivet Cloud or self-host Rivet
  2. Select Vercel
  3. Follow instructions to deploy the Vercel starter template or integrate Rivet into your existing Next.js application

FAQ

  • Do Rivet Actors scale to zero? Yes. Actors run as a Vercel Function invocation. When no actors are active, no Vercel Functions will be running.
  • Do Rivet Actors have coldstarts? No. Vercel's platform enables Rivet Actors to scale to zero without coldstarts.
  • Do I pay for Vercel Function invocation time for the entire lifespan of my Rivet Actor? No. Rivet Actors go to sleep when not in use and wake up immediately when activated again.
  • Can Rivet Actors live longer than Vercel Function timeouts? Yes, actors have a transparent migration system that allows it to migrate between processes in order to live longer than your timeout.
  • How does Rivet make WebSockets work on Vercel? Rivet's tunneling technology works similar to tools like Ngrok or Tailscale which enables us to achieve advanced routing, including support for WebSockets.
  • Do you support Durable Objects-like WebSocket hibernation? Not yet. When we do, this will enable Rivet to keep WebSockets open while your actors go to sleep, therefore significantly saving on invocation time for idle sockets (e.g. notifications, dead chats).
  • Can I self-host Rivet and use it with Vercel? Yes.
  • Does Rivet integrate with Vercel's preview deployments? Not yet. When available, Rivet will automatically provision isolated actor environments for each preview deployment, at no additional cost thanks to scale-to-zero architecture.

Support