Agent vs Registry

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).

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

Registry pubsub may be an interesting option - though I haven’t looked at it in detail (if I’m reading the source correctly, 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”).

3 Likes