liveBook · Manning

Global registration

As explained in Elixir in Action, Third Edition

Global registration is the association of a process with a name that is visible and resolvable across all nodes in a cluster.

Global registration gives a process a cluster-wide alias so clients can discover the same server regardless of node. It extends the ordinary client-server pattern—find a PID, then send a message—into a multinode system. For a distributed to-do cache, one process can own each list, such as {:todo_list, "bob"}. section 12.1.3 section 12.2.2

Global registration behaves like a cluster-aware process registry:

  • Register an arbitrary term as an alias with :global.register_name/2; a successful registration returns :yes. section 12.1.3
  • Resolve the alias from any connected node with :global.whereis_name/1. section 12.1.3 section 12.2.2
  • Reject competing registrations for an existing alias, preserving one registered process per name unless the process crashes. section 12.1.3 section 12.2.2
  • Coordinate registration with a cluster-wide lock, an alias check, notifications to all nodes, and inter-node messages; this creates coordination chatter. section 12.1.3

Registering distributed to-do servers

Name a GenServer with {:global, {Todo.Server, name}} and resolve it through :global.whereis_name/1. Replacing a local Registry registration with this global name lets Todo.Cache discover or start the same list server across the cluster. section 12.2.2

iex(node1@localhost)10> :global.register_name({:todo_list, "bob"}, self())
:yes

Inspect a successful registration, then compare it with the failed duplicate registration and remote lookup. section 12.1.3

How Elixir in Action, Third Edition covers it

How deep it goes
Explains aliases, lookup, duplicate rejection, and cluster-wide locking, then applies the mechanism to GenServer-based services.
Examples
Uses Bob’s to-do list, duplicate registrations on two nodes, remote alias lookup, and global naming for Todo.Server.
What it assumes
Assumes PIDs, message-based client-server communication, local Registry, and connected nodes; teaches the cluster-aware replacement.
What you can do after
Apply it via :global to register and locate one named GenServer across connected cluster nodes.
How it connects
Connects process discovery with Registry, GenServer, DynamicSupervisor, process groups, and distributed publish-subscribe.

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.