:pg solves clustered process discovery when several processes must represent the same service or replicated data. It creates arbitrarily named, cluster-wide groups, propagates membership across connected nodes, and exposes group members for later requests. section 12.1.3
Use the group as a coordination boundary:
- Start :pg on each participating node. section 12.1.3
- Join processes with an arbitrary group term and each process PID. section 12.1.3
- Query the group with :pg.get_members/1, then send updates to every replica or queries to one member. section 12.1.3
iex(node1@localhost)2> :pg.join({:todo_list, "bob"}, self())
:ok
iex(node2@localhost)3> :pg.join({:todo_list, "bob"}, self())
:ok
See two node-local processes join the same {:todo_list, "bob"} group. section 12.1.3
