:global provides cluster-wide process registration and discovery. A process registered under an arbitrary term can be found from any connected node, enabling clients to locate one server for a distributed resource. section 12.1.3 section 12.2.2
Use :global when the operational requirement is a single discoverable process or coordinated access across connected nodes:
- Register a process with :global.register_name/2; competing registration of the same alias fails. section 12.1.3
- Resolve an alias with :global.whereis_name/1, or address a GenServer through {:global, alias}. section 12.1.3
- Coordinate mutually exclusive work with :global.set_lock/1, :global.del_lock/1, or :global.trans/2. section 12.1.5
- Prefer :pg when several processes should share one cluster-wide alias, such as a distributed process group. section 12.2.2
One to-do server per list
Give each server a global alias such as {:global, {Todo.Server, "bob"}}. Todo.Server.whereis/1 calls :global.whereis_name/1 and converts :undefined to nil; Todo.Cache first checks that alias, then starts the child and accepts {:already_started, pid}. Every node therefore resolves Bob’s list to the same process until it crashes. section 12.2.2
