Distributed Actors
Kameo’s distributed actor system enables actors to communicate seamlessly across different nodes in a decentralized network. This architecture provides a powerful foundation for building fault-tolerant, scalable, and resilient distributed systems. At its core, Kameo leverages libp2p for peer-to-peer communication and a decentralized actor registry.
Key Components
- ActorSwarm: The central structure responsible for managing peer-to-peer communication between nodes. It initializes the libp2p swarm, manages connections, and coordinates actor registration and message routing.
- RemoteActorRef: A reference to an actor that resides on a remote node. This reference abstracts away the networking details and allows you to interact with remote actors using familiar APIs.
- Multiaddress: libp2p uses multiaddresses to specify how nodes can be reached using different network protocols like TCP, WebSockets, or QUIC. Multiaddresses are essential for routing messages between nodes.
- Kademlia DHT: Kameo uses Kademlia DHT to store and retrieve actor registration details. When an actor is registered, its name is stored as a key in the DHT, and the value contains information about how to reach the actor, making it discoverable by other nodes.
How Distributed Actors Work
-
Bootstrapping the Actor Swarm: Each node in the network must initialize an
ActorSwarm
to participate in the distributed system. The swarm manages the libp2p connections and allows the node to register actors and send/receive messages. -
Actor Registration: After bootstrapping the swarm, actors can be registered under unique names. Once registered, the actor’s address is propagated through the Kademlia DHT, making it discoverable by other nodes.
-
Remote Messaging: Once an actor is registered, other nodes can look it up and send messages to it. The
RemoteActorRef
allows you to send and receive messages across the network without worrying about the underlying networking.
Why Use Distributed Actors?
Distributed actors are ideal for building systems that need to scale horizontally across multiple machines or geographic locations. They enable fault-tolerant systems, as nodes can fail or be added without disrupting the overall network. Some common use cases for distributed actors include:
- Real-Time Systems: Chat systems, multiplayer games, and real-time data monitoring where actors need to communicate with low latency.
- Microservices Architecture: Building independent services that communicate via message passing, while maintaining resilience to failures.
- IoT Systems: Distributed control systems where devices communicate with each other using lightweight actors.
Key Benefits
- Decentralized Architecture: No single point of failure. Actors can be registered, discovered, and messaged from any node in the network.
- Fault Tolerance: The system continues to operate even if nodes fail or become unreachable. Actor registration via Kademlia DHT ensures nodes can find each other.
- Scalability: Add more nodes to the swarm to handle more actors and distribute load across the network.
- Flexible Networking: By using libp2p, Kameo supports various network protocols, allowing it to adapt to different environments and infrastructure.
What’s Next?
Now that you have an understanding of how distributed actors work, you’re ready to dive deeper into the specifics of setting up the actor swarm, registering actors, and messaging across nodes.
Explore the next section on Bootstrapping the Actor Swarm to get started with setting up your distributed actor system.