zeroexcuses
-
I am looking for something more useful than “just use Phoenix.PubSub”
-
I understand there are various security issues. For our definition of ‘minimal’, let us consider the following operations:
control: HashMap<Channel, HashSet<Client>>
fn send_msg(c: Channel, msg: Msg) {
for client in control.get(c) {
client.send(msg);
}
}
fn add_channel(c: Channel) {
control.insert(c);
}
fn del_channel(c: Channel) {
send_msg(c, "exit");
control.delete(c);
}
fn add_client(c: Channel, client: Client) {
control[c].insert(client);
}
fn del_client(c: Channel, client: Client) {
control[c].del(client);
}
- Now, here is the question. How do we make this distributed ? How do we shard the ‘control’? How do messages get routed to the right place?
I am looking for things on the level of pseudocode/working-code (not informal English descriptions).
Any recommendations for tutorials / books that works through the design / implementation of such a system ?
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
Hey there,
It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Quite interesting article Google brought me. Didn’t find any mentions about it here.
What do you think in general? Would you use togethe...
New
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New
:warning: Security advisory: Decimal DoS vulnerability
A vulnerability has been published for decimal where very large exponents can cau...
New
What IDE or editor are you using for Elixir development?
Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
Other Trending Topics
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dorgan
I’d recommend checking out the erlang :pg module, which is what Phoenix PubSub uses under the hood in one of it’s adapters.
This module implements distributed process groups. A process can subscribe to a group(which could be your topic, following the phoenix pubsub analogy), and you can fetch all the members of a group and send them a message to do a broadcast. The groups list is managed by
:pgitself, so you don’t have to worry about adding them and doing cleanup.A minimal implementation of your use case would be:
Note that
add_channelanddel_channelare not needed, as that’s handled automatically by:pg.Distribution is handled automatically by Elixir, since you can send messages between nodes and it’s managed by erlang’s distribution.
If what you want is to implement something like that from scratch, then you’d need to implement the channels bookkeeping and whatever kind of consistency guarantees you need, as the rest is just regular message passing. I have never done this myself so I don’t have any code snippets to share.
zeroexcuses
For anyone curious: otp/lib/kernel/src/pg.erl at master · erlang/otp · GitHub – this looks really helpful. Thanks!
zeroexcuses
If someone more versed in Erlang/OTP than me could jump in, where exactly in otp/lib/kernel/src/pg.erl at master · erlang/otp · GitHub (which line) is the ‘HashMap<Channel, HashSet>’ stored ?
lud
I guess it is implemented using ETS:
max-au
In
pg, ETS is only a cache to circumvent message passing, and speed upget_memberswhile making it really concurrent.Source of truth - map “Group => [Pid1, Pid2, Pid3, …]” is stored as a part of
pgprocess state: otp/lib/kernel/src/pg.erl at master · erlang/otp · GitHubSince
pgis expected to be used for highly distributed use-cases, this map is added per “scope process”, implementing overlay networks (see some older documentation here: spg/README.md at master · max-au/spg · GitHub )