# Actor distribution question

**URL:** <https://discuss.akka.io/t/actor-distribution-question/3690>\
**Category:** Akka Cluster\
**Created:** [March 18, 2019, 8:12am UTC](https://discuss.akka.io/t/actor-distribution-question/3690 "2019-03-18T08:12:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tg44](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/tg44/32/1099_2.png) [@tg44](https://discuss.akka.io/u/tg44)\
**Post date:** [March 18, 2019, 8:12am UTC](https://discuss.akka.io/t/actor-distribution-question/3690/1 "2019-03-18T08:12:37Z")

</div>

Hy!

If I have N node, and want to start M actor evenly distributed with the knowledge of each created actors ref, how would you do that? Its definitly not a pool, and I think its not even a group. At the point in time I want to create the exact number of actors on the currently living nodes, send them specified messages, and subscribe to the lifecycle events.

---

<div class="post-metadata">

**Author:** ![chbatey](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/chbatey/32/98_2.png) [@chbatey](https://discuss.akka.io/u/chbatey)\
**Post date:** [March 18, 2019, 9:30am UTC](https://discuss.akka.io/t/actor-distribution-question/3690/2 "2019-03-18T09:30:16Z")

</div>

You could run a single “manager” actor on each node that is responsible for creating the M child actors. They could be looked up either via a known path of via communicating via the manager. Alternatively if the exact distribution isn’t important then you could use Cluster Sharding and communication to N\*M sharded actors that will be some what evenly distributed.

---

<div class="post-metadata">

**Author:** ![tg44](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/tg44/32/1099_2.png) [@tg44](https://discuss.akka.io/u/tg44)\
**Post date:** [March 18, 2019, 10:10am UTC](https://discuss.akka.io/t/actor-distribution-question/3690/3 "2019-03-18T10:10:35Z")

</div>

Just for clarification, I don’t want N\*M actor just M.

So you would do something like:

- `A` actor is getting a job
- `A` actor looks up the `Managers` on the living nodes
- `A` actor calculates the number of tasks, and the “best” distribution
- `A` actor requests `Task` actors from the `Managers`
- `Manager` creates `Task` actors
- `Task` actors tells `A` actor that they are ready to work
- `A` actor subscribe to the `Task` actors lifecycle events
- `A` actor distributes the task to the `Task` actors

This is what I came up on my own too, but it seems like a general pattern to me, that is the reason I asked the question. (It’s nice to recreate existing things to learn how they works, but if there an already working build-in thing for that I would use that instead :D )

---

<div class="post-metadata">

**Author:** ![TimMoore](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/timmoore/32/7_2.png) [@TimMoore](https://discuss.akka.io/u/TimMoore)\
**Post date:** [March 18, 2019, 8:56pm UTC](https://discuss.akka.io/t/actor-distribution-question/3690/4 "2019-03-18T20:56:38Z")

</div>

You can see how Lagom implements this in `ClusterDistribution`:

> <https://github.com/lagom/lagom/blob/master/persistence/core/src/main/scala/com/lightbend/lagom/internal/persistence/cluster/ClusterDistribution.scala>
