liveBook · Manning

Process discovery

As explained in Elixir in Action, Third Edition

Process discovery is the identification of a process so that other processes can communicate with it.

Process discovery identifies a server process so another process can communicate with it. The usual flow is simple: obtain the server’s PID, then send it a message. Registration replaces explicit PID passing with a stable name, simplifying process interfaces and supporting systems where processes restart or run across nodes. section 12.1.3 section 5.3.5

Choose the discovery scope that matches the system:

  • Use local registration when the target process lives on the same node. Process.register/2 assigns a name, and messages can then be sent to that name instead of a PID. section 5.3.5
  • Use :global for cluster-wide aliases. It prevents competing registrations, informs all nodes, and exposes the process through :global.whereis_name/1. section 12.1.3
  • Treat global registration as coordination with overhead: acquiring a cluster-wide lock and broadcasting registrations requires messages between nodes. section 12.1.3

Naming a to-do server

A local TodoServer can register under :todo_server so interface functions send requests by name rather than receiving and storing its PID. In a cluster, {:todo_list, "bob"} can serve as a global alias, allowing processes on every node to locate Bob’s single to-do-list process. section 5.3.5 section 12.1.3

GenServer.start_link(
  __MODULE__,
  arg,
  name: {:global, some_global_alias}                 #1
)
 
GenServer.call({:global, some_global_alias}, ...)    #2

GenServer accepts a global registration name at startup and the same name for later calls, making cluster-wide discovery visible in the server interface. section 12.1.3

How Elixir in Action, Third Edition covers it

How deep it goes
Explains PID lookup, local registration, global coordination, and messaging overhead, but stops short of implementation code for the registry.
Examples
Uses a registered TodoServer, a global Bob to-do-list alias, and cross-node lookup and membership demonstrations.
What it assumes
Assumes familiarity with BEAM processes, PIDs, message sending, and basic client-server interaction.
What you can do after
Apply it via Process.register/2, :global, and named GenServer calls to avoid passing server PIDs explicitly.
How it connects
Connects process registries, GenServer, messaging, restarting processes, and distributed systems.

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.