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 aBroadcast envelope. Use Tell to send:
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 viaAsk).
Spawning a Router
UseSpawnRouter on the actor system:
name– Router actor namepoolSize– Number of routees to spawn (must be > 0)routeesKind– Actor type for routees (a pointer to a struct implementingActor)opts– Router options (see below)
Router Options
Examples
Control Messages
Routers accept these control messages viaTell or Ask:
GetRoutees
AdjustRouterPoolSize
poolSize > 0: Add that many routeespoolSize < 0: Remove that many routeespoolSize == 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
StatusFailureif the deadline expires or all routees fail
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 aPanicSignal 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