I think the main problem here is that you are using Phoenix.PubSub (endpoint.broadcast), which is precisely what it says it is: a pub-sub mechanism. The pub-sub mechanisms generally are fire and forget, and Phoenix does it precisely this way. So, if you want to listen to some ack message it is up to you for implementation and it won’t be super easy, as you have to handle timeouts, out-of-order messages etc.
What I would do instead is to maybe register process globally within a cluster and then perform a normal GenServer.call. GenServer already sets up monitor on the destination process, and will error if the
pid you are trying to send message to crashes, it also waits for the response blocking so after your
GenServer.call finishes, you will be sure the destination process did in fact receive message and didn’t crash processing it.
There is a number of ways to perform gluster-wide process registration, and maybe you’d need grouping them too. There’s
Horde.Registry but also
:global and others. I would have a look at Horde as this is what I am using and works pretty much flawlessly in my, relatively simple, scenarios.