Skip to content

🎭 Stateful serverless framework for Rivet, Cloudflare Workers, Bun, and Node.js. Build AI agents, realtime apps, game servers, and more.

License

Notifications You must be signed in to change notification settings

rivet-gg/actor-core

Repository files navigation

ActorCore

Stateful, Scalable, Realtime Backend Framework

GitHub Discussions Discord Rivet Twitter Rivet Bluesky License Apache-2.0

Intro

The modern way to build multiplayer, realtime, or AI agent backends.

Runs on Rivet, Cloudflare Workers, Bun, and Node.js. Integrates with Hono and Redis.

Architecture

  • πŸ’Ύ Persistent, In-Memory State: Fast in-memory access with built-in durability β€” no external databases or caches needed.
  • ⚑ Ultra-Fast State Updates: Real-time state updates with ultra-low latency, powered by co-locating compute and data.
  • πŸ”‹ Batteries Included: Integrated support for state, actions, events, scheduling, and multiplayer β€” no extra boilerplate code needed.
  • πŸ–₯️ Serverless & Scalable: Effortless scaling, scale-to-zero, and easy deployments on any serverless runtime.

Features

  • πŸ’Ύ State: Fast in-memory access with built-in durability.
  • πŸ’» Actions: Callable functions for seamless client-server communication.
  • πŸ“‘ Events: Real-time event handling and broadcasting.
  • ⏰ Scheduling: Timed tasks and operations management.
  • 🌐 Connections & Multiplayer: Manage connections and multiplayer interactions.
  • 🏷️ Metadata: Store and manage additional data attributes.

Everything you need to build realtime, stateful backends

ActorCore provides a solid foundation with the features you'd expect for modern apps.

Feature ActorCore Durable Objects Socket.io Redis AWS Lambda
In-Memory State βœ“ βœ“ βœ“ βœ“
Persisted State βœ“ βœ“
Actions (RPC) βœ“ βœ“ βœ“ βœ“
Events (Pub/Sub) βœ“ - βœ“ βœ“
Scheduling βœ“ - -
Edge Computing βœ“ † βœ“ βœ“
No Vendor Lock βœ“ βœ“ βœ“

- = requires significant boilerplate code or external service

† = on supported platforms

Quickstart

Run this command:

npx create-actor@latest

Supported Platforms

Overview

Create Actor

import { actor, setup } from "actor-core";

const chatRoom = actor({
  state: { messages: [] },
  actions: {
    // receive an action call from the client
    sendMessage: (c, username: string, message: string) => {
      // save message to persistent storage
      c.state.messages.push({ username, message });

      // broadcast message to all clients
      c.broadcast("newMessage", username, message);
    },
    // allow client to request message history
    getMessages: (c) => c.state.messages
  },
});

export const app = setup({
  actors: { chatRoom },
  cors: { origin: "http://localhost:8080" }
});

export type App = typeof app;

Connect to Actor

import { createClient } from "actor-core/client";
import type { App } from "../src/index";

const client = createClient<App>(/* manager endpoint */);

// connect to chat room
const chatRoom = await client.chatRoom.get({ channel: "random" });

// listen for new messages
chatRoom.on("newMessage", (username: string, message: string) =>
  console.log(`Message from ${username}: ${message}`),
);

// send message to room
await chatRoom.sendMessage("william", "All the world's a stage.");

Community & Support

License

Apache 2.0