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
