liveBook · Manning

:global

As explained in Elixir in Action, Third Edition

:global is an Erlang runtime module that provides globally visible process registration and discovery across connected nodes.

: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

How Elixir in Action, Third Edition covers it

How deep it goes
Explains registration, lookup, locking, implementation chatter, and application integration, while deferring broader distribution internals.
Examples
Uses connected IEx nodes, competing to-do aliases, GenServer calls, distributed to-do servers, and mutually exclusive lock transactions.
What it assumes
Assumes process communication and local Registry-based discovery, then extends those patterns to connected nodes.
What you can do after
Apply it via :global to register, locate, address, and coordinate processes across connected Erlang nodes.
How it connects
Connects process discovery with Registry, GenServer, DynamicSupervisor, :pg, message passing, and cluster-wide locks.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elixir in Action, Third Edition. The section links point to the parts of the book it draws on.