A process registry maps application-defined keys to process identifiers. It gives clients a stable discovery point instead of requiring them to retain a worker PID that may change after a supervisor restarts the worker. section 9.1.2
A local registry supports a practical communication workflow:
- Start the registry as a supervised process and choose a registry name plus unique or duplicate key semantics. section 9.1.2 section 9.1.4
- Register each worker under an arbitrary term such as {:database_worker, 1}, usually during initialization. section 9.1.2
- Look up the key to obtain the current PID, then send a message or make a GenServer call. section 9.1.2 section 9.1.3
- Start the registry before dependent workers, because supervisor child processes start synchronously in specification order. section 9.1.4
Elixir’s Registry accepts arbitrary complex keys, unlike ordinary local registration, which is limited to atoms. A via tuple connects those keys to OTP APIs: GenServer resolves the registry entry when starting, calling, or casting to a process. section 9.1.2 section 9.1.3
Registering supervised database workers
Define a small registry wrapper with start_link/0, via_tuple/1, and child_spec/1. Start it before the database workers. Each worker receives a {db_folder, worker_id} argument and starts with name: via_tuple(worker_id). Client functions can then call GenServer.cast or GenServer.call with the same registry-backed name rather than a stored PID. section 9.1.4
Use the process-discovery diagram to trace registration, lookup, and message delivery across worker restarts. section 9.1.2
The abstraction remains local to one node. Cluster-wide discovery requires another mechanism, such as Erlang’s :global for one registered process or :pg for groups of processes. section 12.1.3
