Registry Processes

Learn the registry processes, including how to name them, the types of naming techniques, and how to start them.

Name processes using the Registry

Until now, we used the process identifier obtained from starting the process to interact with it. However, we can optionally provide a :name value when starting a process. This can be used later instead of a PID. This way, we don’t have to keep track of the PIDs of the processes we start. Functions like GenServer.cast/2 and GenServer.call/3 also accept a name instead of a process identifier, and we’ve already seen how to use Process.whereis/1 to find out the PID for JobRunner.

To make working with names easier, Elixir comes with a module called Registry. It’s an efficient key-value store with some useful functionality. Let’s see how we can use it.

Processes can be named when they start via the :name option. This is what we did when creating JobRunner:

children = [
   {DynamicSupervisor, strategy: :one_for_one, name: Jobber.JobRunner},
]

Get hands-on with 1200+ tech skills courses.