Skip to main content

Concept

You interact with actors through a *PID. You don’t need to know whether the actor is local (same process) or remote ( another node). The same Tell/Ask APIs work in both cases.

How it works

  • Local: Message is enqueued directly into the actor’s mailbox.
  • Remote: Message is serialized, sent over TCP, deserialized on the target node, and enqueued there.
The caller uses the same pid.Tell(msg) or pid.Ask(ctx, msg, timeout) regardless of location.

The Path interface

pid.Path() returns a Path interface: the location-transparent actor identity:
The Path interface
Use Path() for host, port, name, and string representation. QualifiedName() returns the name that identifies the actor within its system, parent/child for a child, which is the name ActorOf, ActorExists, Kill and ReSpawn resolve. Guard for nil when the sender is unknown (e.g., NoSender).

When location matters

Use pid.IsLocal() or pid.IsRemote() when you need location-specific behavior (e.g., avoiding remote calls for hot paths, or logging).

ActorOf

ActorOf(ctx, name) returns a *PID whether the actor is local or remote. The framework looks up the actor in the local tree first, then in the cluster registry. You get a unified handle either way. For a top-level actor, name is its name. A child’s name is unique only among its siblings, so two parents can each have a child called worker. A child is found by its qualified name, the names of its ancestors and its own joined by /, from any node: ActorOf(ctx, "orders/worker"). actor.QualifiedName("orders", "worker") builds that name and rejects a name Spawn would reject, and pid.Path().QualifiedName() reports it for a running actor. On the node that hosts it, a child is also found by its bare name; when several children on that node share it, the most recently spawned one is returned. ActorExists, Kill and ReSpawn resolve names the same way.