Erlang / Erlang Advanced Interview questions
How does the global module handle process name registration across a cluster?
The global module extends Erlang's local process registry (register/2) across an
entire distributed cluster: global:register_name/2 makes a PID discoverable by name from any
connected node, not just the one it was spawned on.
global:register_name(payment_processor, self()), %% from any node in the cluster: Pid = global:whereis_name(payment_processor).
To keep the name table consistent across nodes, global synchronizes registrations between all
connected nodes and resolves simultaneous registration conflicts (two nodes registering the same name at
nearly the same time) by calling a configurable resolver function, defaulting to keeping whichever registration
happened first and killing the later, conflicting one. This synchronization has a real cost: registering or
looking up global names is significantly slower than local register/2, since it may require
cluster-wide coordination.
More Related questions...