Virtual Actors
Virtual Actors in Dapr provide a programming model for managing stateful objects at scale. Each actor is a single-threaded object with its own state and logic, managed by the Dapr runtime.
Key Features
- Simplifies concurrency by ensuring one thread per actor
- Automatic state persistence
- Scales to millions of actors
- Built-in timers and reminders
Example Usage
- C#
- Java
- Python
// Define and use a Dapr actor
public interface IOrderActor : IActor
{
Task SubmitOrderAsync(Order order);
}
// Call actor method
var proxy = ActorProxy.Create<IOrderActor>(actorId, "OrderActor");
await proxy.SubmitOrderAsync(order);
// Define and use a Dapr actor
public interface OrderActor {
Mono<Void> submitOrder(Order order);
}
// Call actor method
OrderActor proxy = new ActorProxyBuilder<>(OrderActor.class, "OrderActor").build(actorId);
proxy.submitOrder(order).block();
# Dapr Python SDK does not yet support actors, but you can interact with actors via HTTP/gRPC APIs.
Real-World Application
You use Virtual Actors to model entities such as users, devices, or orders. Each actor maintains its own state, making it easy to build scalable, stateful applications.
Related Links
Was this page useful?