Skip to main content

Concept

A router is an actor that fans out messages to a pool of routees using a routing strategy. You send messages to the router; it forwards them to one or more routees according to the configured strategy. Routers are not cluster-relocatable. If the host node leaves or crashes, the router and its routees are not automatically re-spawned elsewhere.

Sending Messages

Messages to a router must be wrapped in a Broadcast envelope. Use Tell to send:
The router unwraps the payload and dispatches it to its routees based on the routing strategy.

Routing Strategies

Standard Strategies (Fire-and-Forget)

These strategies never wait for replies. They are fire-and-forget; routees process messages asynchronously.

Reply-Based Strategies

When you need the router to observe replies and relay the first successful response back to the sender, use one of these. Outcomes are delivered asynchronously to the sender as ordinary messages (not via Ask).

Spawning a Router

Use SpawnRouter on the actor system:
Parameters:
  • name – Router actor name
  • poolSize – Number of routees to spawn (must be > 0)
  • routeesKind – Actor type for routees (a pointer to a struct implementing Actor)
  • opts – Router options (see below)

Router Options

Examples

Control Messages

Routers accept these control messages via Tell or Ask:

GetRoutees

AdjustRouterPoolSize

  • poolSize > 0: Add that many routees
  • poolSize < 0: Remove that many routees
  • poolSize == 0: No-op

Handling Replies (Scatter-Gather / Tail-Chopping)

For reply-based strategies, the sender receives either:
  • The first successful reply from a routee (as a normal message)
  • A StatusFailure if the deadline expires or all routees fail
Handle both in your actor’s Receive:

When to Use

  • Load balancing – RoundRobin or Random across a pool of workers
  • Sticky sessions / partition affinity – ConsistentHash when messages with the same key (e.g. order ID, customer ID) must always go to the same routee
  • Parallel processing – FanOut for pub/sub, cache invalidation, multi-sink processing
  • Fastest responder – Scatter-Gather First when you want the first successful reply
  • Controlled probing – Tail-Chopping when you prefer sequential probing with bounded fan-out

Routee Supervision

When a routee panics, the router receives a PanicSignal and applies the configured directive:
  • Stop (default): Terminate the routee and remove it from the pool
  • Restart: Restart the routee (with retry limits)
  • Resume: Keep the routee and continue processing
If all routees are stopped and none remain, the router shuts down and unhandled messages go to the deadletter.