Introduction
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:
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.