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.

Supports Rivet, Cloudflare Workers, Bun, and Node.js.

Architecture

  • πŸ’Ύ Durable, 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, RPC, 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.
  • πŸ’» RPC: Remote procedure calls 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.

What makes ActorCore different?

ActorCore is the modern way to build realtime, stateful backends.

Feature ActorCore Durable Objects AWS Lambda Redis Socket.io
In-Memory State βœ“ βœ“ βœ“ βœ“
Durable State βœ“ βœ“
RPC βœ“ βœ“ βœ“ βœ“
Events βœ“ βœ“
Scheduling βœ“
Edge Computing βœ“ † βœ“ βœ“
No Vendor Lock βœ“ βœ“ βœ“

† = on supported platforms

Getting Started

Step 1: Installation

# npm
npm add actor-core

# pnpm
pnpm add actor-core

# Yarn
yarn add actor-core

# Bun
bun add actor-core

Step 2: Create an Actor

import { Actor, type Rpc } from "actor-core";

export interface State {
  messages: { username: string; message: string }[];
}

export default class ChatRoom extends Actor<State> {
  // initialize this._state
  _onInitialize() {
    return { messages: [] };
  }

  // receive an remote procedure call from the client
  sendMessage(rpc: Rpc<ChatRoom>, username: string, message: string) {
    // save message to persistent storage
    this._state.messages.push({ username, message });

    // broadcast message to all clients
    this._broadcast("newMessage", username, message);
  }
}

Step 3: Connect to Actor

import { Client } from "actor-core/client";
import type ChatRoom from "../src/chat-room.ts";

const client = new Client(/* manager endpoint */);

// connect to chat room
const chatRoom = await client.get<ChatRoom>({ name: "chat" });

// 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.");

Step 4: Deploy

Deploy to your platform of choice:

Community & Support

License

Apache 2.0