Getting Started

What are Actors?

Actors are a simple and powerful architecture. Think of actors as independent workers that:

  • Maintain their own isolated, durable state in memory (survives crashes and upgrades)
  • Communicate only through remote procedure calls - no shared state
  • Scale infinitely, start instantly, and sleep when not in use
  • Deploy globally at the edge (close to users)

These characteristics provide the following benefits:

  • Complex infrastructure (e.g., caches, queues, pub/sub) can be replaced with actors, which is a simpler architecture
  • Improve performance by combining compute (i.e., "RPC") with data (i.e., "state")
  • Provide natural fault tolerance - state is durable and failures don't cascade
  • Lower latency for users by running at the edge and combining compute/data

Core concepts

  • Remote Procedure Call (RPC) is how clients communicate with actors and how actors communicate with each other.
  • State is the data belonging to each actor. State cannot be shared between actors. State is stored in memory (unless it's too large) for fast reads and writes. State is durable and will always survive a crash or upgrade. You can update state without having to do anything special.
  • Events are used for real-time communication between clients and actors. Clients can subscribe to events with actor.on("myEvent"), and actors can publish events with this.broadcast("myEvent") or connection.send("myEvent").
  • Connections represent a client that's currently connected to the actor. Connections have their own state, e.g., userId. You can use onConnect to authenticate connections before they can communicate with the actor.

To read more about architecting actors for scale, see here.


Actor architecture vs. server and container architecture

Servers and containers and actors handle state and compute very differently:

FeatureServers and ContainersActors
Compute and StateSeparate compute (application layer) from state (databases)Keep state and compute together
ScalingNeed external services (load balancers, databases) to scaleCheaper & automatically distribute load
PerformancePerformance can be limited by network latency & complex locking mechanismsOptimized performance by co-locating compute and state
LatencyTypically higher latency due to centralized data centers & databaseLower latency by deploying at the edge, closer to users
High AvailabilityNeed manual configuration for high availability and fault toleranceProvide built-in durability for crashes and fault isolation to prevent cascading failures
Resource EfficiencyRun continuously regardless of load, wasting resources when idleAutomatically sleep when inactive and wake instantly when needed
DevOps OverheadRequires significant DevOps effort for setup and maintenanceMinimal DevOps overhead due to simpler, on-demand architecture

Builds

Builds contain the code required to run an actor. Builds are uploaded to Rivet when running rivet deploy. Each actor is associated with a single build ID.

When a new build is uploaded, all actors are upgraded to use the new build. This process is usually transparent to you since the state is durable.


Actor and build tags

Tags are a powerful way of managing actors at scale. Tags can be any set of key-value pairs you choose. They allow you to easily choose which actors to communicate with, create fine-grained security rules, and enhance monitoring.

Structuring tags

While you can choose anything you'd like for your actor's tags, here are a few guidelines to consider:

  • Actors and builds almost always have a name tag defining what type of actor this is. For example, name=user, name=channel, or name=document. An actor's name tag is usually identical to the build's name tag.
  • Actors often have a unique ID associated with them as a tag. For example, userId=1234, channel=memes, documentId=1234.
  • Actors and builds sometimes have an owner tag indicating what service created the actor. For example, owner=api and owner=terraform.
  • For larger projects, actors and builds sometimes have an app tag to group the product an actor belongs to together. For example, app=social and app=store.

Example architectures

See the use cases for explanations of example actor architectures.


Next steps