Erlang / Erlang Advanced Interview questions
What is the pg (process groups) module used for?
pg lets multiple processes join a named group, cluster-wide, so a caller can broadcast or fan
out work to every member without tracking individual PIDs itself — unlike global, which
maps one name to exactly one process, pg maps one name to a set of processes.
pg:join(chat_room_42, self()), Members = pg:get_members(chat_room_42), [Pid ! {new_message, Msg} || Pid <- Members].
Typical uses include pub/sub-style fan-out (every subscriber process in a group gets a copy of an event) and
worker pools where any member can pick up a task. It's deliberately simpler than global: it makes
no attempt at strong consistency guarantees during partitions, favoring availability and low overhead, which
fits well for use cases like broadcast messaging where an occasional stale group view is tolerable.
More Related questions...