Write Once, Deploy Anywhere: Topology-Transparent Actor Design

One of the hardest problems in distributed actor systems is writing actors that work in development and production without code changes. Most frameworks leak deployment details into actor code: an actor written against a local reference has to be rewired to reach one across the network, and an actor tested alone needs different wiring in integration tests. MLambda keeps the topology out of the actor.

The problem: topology-aware actors

Getting hold of another actor usually looks different depending on where it lives: a local spawn, a remote path with a host and a port, a factory that assumes a cluster. Each makes the actor know its deployment, which breaks the actor model’s promise that actors are location-transparent.

Routes, not locations

In MLambda an actor is reached by its route: greeter/en, account/alice. A route says which actor, never where. A class declares its route template, and a host declares what it hosts:

@route("account/{id}")
instance Actor Account where
  type Message Account = Hosted
  ...

hostings :: [Hosting]
hostings = [hostingOf accountOf]

A client asks the route:

askRoute client "account/alice" "String" payload 5000

One client, three topologies

askRoute takes an ActorClient, and every host gives one:

Topology The client Where account/alice runs
Standalone LocalClient Here; made the first time it is asked
Cluster RemoteClient, through an asteroid On a satellite a cluster node chose
Hybrid RemoteClient, through this node’s asteroid On whichever node’s satellite runs it, maybe this one

The scenario code in MLambda.Actor.Demo takes an ActorClient and runs unchanged in all of them. Only the host, chosen by DEMO_ROLE or ACTOR_TOPOLOGY, differs.

How a cluster finds the actor

  1. A satellite registers with its cluster nodes, listing the route templates it can run.
  2. The cluster nodes share a route table, a CRDT, by gossip, so every node knows which routes exist and who owns them.
  3. An ask for an unknown route has the least loaded satellite that can run it make the actor; the route then enters the table.
  4. Later asks, through any cluster node, go to that actor.
  5. A satellite that stops heartbeating is dropped after 15 seconds; its routes are made again elsewhere on the next ask.

None of this is visible to the actor or its caller.

In tests

A test uses a standalone host, or the actor directly through actorOf. Integration tests run the same scenario in Docker compose against a real cluster. Same code, different configuration.