Finding Processes

Look at the details of processes and practice it.

When building distributed systems with Elixir, naming and grouping processes is fundamental. A process registry lets us uniquely name a process. A process group allows for group processes based on a property or on a shared attribute.

Process registries and process groups store mutable information. After all, a registry can name a process, assign it to a group, or destroy that information at any time. However, process data is still ephemeral. Once a process is dead, its name or group don’t matter. If an asteroid strikes our data center, all name and group information will be lost, but all processes will be gone too.

For process registries and process groups, we don’t need to worry about persistence, but we do need to discuss the trade-offs between local and distributed storage, as well as the strategies for replicating data.

Process registries

A process registry lets us uniquely name a process. There are two kinds of registries.

  1. Local registries:

    They store the names of processes that belong to the current machine.

  2. Distributed registries:

    They store the names of processes across the whole cluster.

Let’s explore some of the registries and their trade-offs, focusing on the registries that are part of the Erlang and Elixir standard libraries.

The local atom-based registry

An atom registry is a tool that binds an atom to a process. In a previous chapter, we defined a PathAllocator which started like this:

Press + to interact
defmodule PathAllocator do
@name PathAllocator
def start_link(tmp_dir) when is_binary(tmp_dir) do
GenServer.start_link(__MODULE__, tmp_dir, name: @name)
end
...
end

When Elixir starts a process and gives it an atom name, such as PathAllocator, it uses the local registry from the Erlang VM. By convention, Elixir names those processes by the module defining them. It does so to simplify introspection and debugging. ...