Overview
Actors combine compute and storage into unified entities for simplified architecture. Actors seamlessly integrate with your existing infrastructure or can serve as a complete standalone solution.
Quickstart
Run this to get started:
What are actors good for?
Actors in ActorCore are ideal for applications requiring:
- Stateful Services: Applications where maintaining state across interactions is critical. For example, Collaborative Apps with shared editing and automatic persistence.
- Realtime Systems: Applications requiring fast, in-memory state modifications or push updates to connected clients. For example, Multiplayer Games with game rooms and player state.
- Long-Running Processes: Tasks that execute over extended periods or in multiple steps. For example, AI Agents with ongoing conversations and stateful tool calls.
- Durability: Processes that must survive crashes and restarts without data loss. For example, Durable Execution workflows that continue after system restarts.
- Horizontal Scalability: Systems that need to scale by distributing load across many instances. For example, Realtime Stream Processing for stateful event handling.
- Local-First Architecture: Systems that synchronize state between offline clients. For example, Local-First Sync between devices.
Core Concepts
In ActorCore, each actor has these key characteristics:
- State Is Automatically Persisted: State automatically persists between restarts, upgrades, & crashes
- State Is Stored In-Memory: State is stored in memory for high-performance reads/writes while also automatically persisted
- Isolated State Ownership: Actors only manage their own state, which can only be modified by the actor itself
- Communicates via Actions: How clients and other actors interact with an actor
- Actions Are Low-Latency: Actions provide WebSocket-like performance for time-sensitive operations
- Broadcast Updates With Events: Actors can publish real-time updates to connected clients
Code Example
Here’s a complete chat room actor that maintains state and handles messages. We’ll explore each component in depth throughout this document:
Using the App
To start using your actor, create an app and serve it:
Key Actor Components
State
Actors maintain state that’s stored in memory and automatically persisted. State is defined either as a constant or via a createState
function:
Update state by modifying c.state
in your actions:
These changes are durable and are automatically persisted across updates, restarts, and crashes.
Learn more about state management.
Actions
Actions are functions defined in your actor configuration that clients & other actors can call:
Each action receives a context object (commonly named c
) as its first parameter, which provides access to state, connections, and other utilities.
Learn more about actions.
Events
Actors can broadcast events to connected clients:
You can also send events to specific clients:
Learn more about events.
Actor Tags
Tags are key-value pairs attached to actors that serve two purposes:
- Actor Discovery: Find specific actors using
client.get(tags)
- Organization: Group related actors for management purposes
For example, you can query chat rooms by tag like:
Common Tag Patterns
Actor Lifecycle
Actors are created automatically when needed and persist until explicitly shutdown.
To shut down an actor, use c.shutdown()
from within an action:
Learn more about the actor lifecycle.