liveBook · Manning

Global alias

As explained in Elixir in Action, Third Edition

A global alias is a name associated with a process and made resolvable across all nodes in a cluster.

A global alias associates a process with an arbitrary term and makes that process discoverable across every connected node in a cluster. It solves cluster-wide process discovery when one process must answer consistently for a given identity. section 12.1.3 section 12.2.2

Global registration trades coordination during registration for fast local lookups:

  • Acquires a cluster-wide lock, checks whether the alias exists, informs all nodes, and releases the lock. section 12.1.3
  • Caches registration information in each node’s local ETS table, so later lookups avoid network chatter. section 12.1.3
  • Rejects a competing registration for the same alias, preserving one cluster-wide process identity. section 12.1.3
  • Fits single-process discovery; use process groups when multiple processes should share one cluster-wide alias. section 12.2.2

Registering and finding a to-do server

Register the current process with :global.register_name({:todo_list, "bob"}, self()). A second node cannot claim the same alias, while :global.whereis_name({:todo_list, "bob"}) returns the registered process PID. GenServer can use {:global, alias} as its name. section 12.1.3 section 12.2.2

Listing 12.2 Global registration of to-do servers (todo_distributed/lib/todo/server.ex)
defmodule Todo.Server do
  ...
 
  def start_link(name) do
    GenServer.start_link(Todo.Server, name, name: global_name(name))
  end
 
  defp global_name(name) do
    {:global, {__MODULE__, name}}     #1
  end
 
  ...
end

Shows the minimal GenServer change that replaces local registration with a global name. section 12.2.2

How Elixir in Action, Third Edition covers it

How deep it goes
Explains registration coordination, local lookup caching, duplicate handling, and GenServer integration, but not broader failure recovery.
Examples
Uses node shells, a Bob to-do-list server, duplicate registration attempts, whereis lookups, and global GenServer naming.
What it assumes
Assumes familiarity with Elixir processes, GenServer, node clustering, and local registries; distinguishes Registry, :global, and :pg.
What you can do after
Configure and operate cluster-wide process discovery through :global registration, lookup, and GenServer naming.
How it connects
Connects process registration with GenServer, DynamicSupervisor, ETS, process groups, and distributed process discovery.

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.