# Agent vs Registry

**URL:** <https://forum.elixirforum.com/t/agent-vs-registry/14211>\
**Category:** Questions\
**Tags:** agent, processes, registry\
**Created:** [May 15, 2018, 3:06pm UTC](https://forum.elixirforum.com/t/agent-vs-registry/14211 "2018-05-15T15:06:39Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![peerreynders](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/peerreynders/32/5826_2.png) [@peerreynders](https://forum.elixirforum.com/u/peerreynders)\
**Post date:** [May 15, 2018, 3:26pm UTC](https://forum.elixirforum.com/t/agent-vs-registry/14211/2 "2018-05-15T15:26:28Z")

</div>

> [@lalo2302](#):
>
> The counter needs to be indepent and accesing it should not interfiere with the process performance.

I think the answer to your problem is _another process_ which is only responsible for the counter.

- The process doing the work notifies its _counter process_ when the count is updated
- Other processes call the _counter process_ to obtain the current state.

Alternately it may make more sense for the _counter process_ to be subscription based - otherwise you are building an “ask architecture” rather than a “tell architecture” ([Tell, Don’t Ask](https://pragprog.com/articles/tell-dont-ask)).

Personally Agents make me queasy because anybody can mess with their internal state which has the smell of “global mutability”.

[Registry pubsub](https://hexdocs.pm/elixir/master/Registry.html#module-using-as-a-pubsub) may be an interesting option - though I haven’t looked at it in detail (if I’m reading the source correctly, [`dispatch/4`](https://hexdocs.pm/elixir/master/Registry.html#dispatch/4) will run in the calling process rather than queuing the function to be executed later within the registry’s process, so I would classify this approach as “interfering with process performance”).

---

_[View the full topic](https://forum.elixirforum.com/t/agent-vs-registry/14211)._
