website/src/content/posts/2025-10-17-rivet-actors-vercel/page.mdx
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.
| Dimension | Rivet Actors on Vercel Functions | Cloudflare Durable Objects | Why it matters |
|---|---|---|---|
| Runtime | Standard Node.js (Vercel Functions), full support with npm packages | Custom runtime (workerd), subset of Node.js APIs, partial support with npm packages | Using standard Node.js makes packages and frameworks "just work" and reduces vendor lock-in. |
| Memory / CPU per actor | Configurable up to 4 GB / 2 vCPU | Per-isolate memory cap 128 MB | Memory-heavy workloads are more feasible on Vercel than on Cloudflare |
| Regional control | Configurable specific regions | DOs can be restricted to broad jurisdictions and accept location hints, though limited control | Explicit control helps reduce latency and meet compliance requirements |
| Lock-in / portability | Open-source actor library designed to be portable across standard runtimes/clouds | DOs run on Cloudflare's runtime and APIs, not open-source, not portable | Open source + standard runtimes provide flexibility, enables migrations, and allows for on-prem deployments |
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.
Running Rivet Actors on Vercel provides many benefits:
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.
A stateful AI chatbot with persistent memory and real-time updates:
<CodeGroup>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 },
});
import { createRivetKit } from "@rivetkit/next-js/client";
import { useEffect, useState } from "react";
import { registry } from "../rivet/registry";
import type { Message } from "../lib/utils";
const { useActor } = createRivetKit<typeof registry>({
endpoint: "https://api.rivet.dev",
namespace: "xxxx",
token: "xxxx",
});
export function AgentChat() {
// Connect to the actor
const aiAgent = useActor({
name: "aiAgent",
key: ["default"],
});
const [messages, setMessages] = useState<Message[]>([]);
const [input, setInput] = useState("");
const [isLoading, setIsLoading] = useState(false);
// Fetch initial messages on load
useEffect(() => {
if (aiAgent.connection) {
aiAgent.connection.getMessages().then(setMessages);
}
}, [aiAgent.connection]);
// Subscribe to realtime events
aiAgent.useEvent("messageReceived", (message: Message) => {
setMessages((prev) => [...prev, message]);
setIsLoading(false);
});
const handleSendMessage = async () => {
if (aiAgent.connection && input.trim()) {
setIsLoading(true);
const userMessage = { role: "user", content: input, timestamp: Date.now() } as Message;
setMessages((prev) => [...prev, userMessage]);
await aiAgent.connection.sendMessage(input);
setInput("");
}
};
return (
<div className="ai-chat">
<div className="messages">
{messages.length === 0 ? (
<div className="empty-message">
Ask the AI assistant a question to get started
</div>
) : (
messages.map((msg, i) => (
<div key={i} className={`message ${msg.role}`}>
<div className="avatar">{msg.role === "user" ? "👤" : "🤖"}</div>
<div className="content">{msg.content}</div>
</div>
))
)}
{isLoading && (
<div className="message assistant loading">
<div className="avatar">🤖</div>
<div className="content">Thinking...</div>
</div>
)}
</div>
<div className="input-area">
<input
value={input}
onChange={(e) => setInput(e.target.value)}
onKeyPress={(e) => e.key === "Enter" && handleSendMessage()}
placeholder="Ask the AI assistant..."
disabled={isLoading}
/>
<button
onClick={handleSendMessage}
disabled={isLoading || !input.trim()}
>
Send
</button>
</div>
</div>
);
}