why
Endpoint.broadcast vs Channel.broadcast
I noticed there are two broadcast/3 functions available in different modules:
MyApp.Endpoint.broadcast(topic, event, message)
Docs: “Broadcasts a msg as event in the given topic to all nodes.”
and
MyApp.Channel.broadcast(socket, event, message)
Docs: “Broadcast an event to all subscribers of the socket topic.”
The main difference seems to be in their use of topic vs socket.
I understand the use case of the first (“send a message to all who subscribe to topic XYZ”).
But what might be the practical use case of the second?
Thank you.
Trending in Questions
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
Hello,
I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New
Other Trending Topics
Beyond Safe Migrations: Better Practices for Ecto + PostgreSQL - Joe Harrow | ElixirConf US 2025
Comments welcome! View t...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 4 of 4 Posts
cenotaph
Documentation explained them succinctly.
When you want to send an update to everyone who wants information about
breaking newsyou would use the endpoint.When you want to send an update to only subscribers who wants information about
ginger catsand reside incat loverschannel, you would use the second one.NobbZ
Both do the same. They have been explained to me as “use
*.Channel.broadcastif you have the socket,*.Endpoint.broadcastotherwise”.why
Interesting, they indeed both broadcast to a topic.
I just looked at the implementation of both, and both use
*.Channel.Server.broadcastunder the hood.*.Endpoint:*.Channel:However, looking at this made me realize that my understanding of how sockets / channels / topics map to one another is incorrect / muddled.
When looking at the above
*.Channelimplementation as well as how the Socket struct is implemented, I notice that there is achannelkey and atopickey (both words singular).Now, I read somewhere that “multiple channels are multiplexed over one socket”. How would that work with the single
channeland singletopickeys in socket?Thanks for any enlightenment
why
I think I developed a clearer understanding now of how socket / channel / topic relate to one another.
In the Channels docs it says:
Additionally, this StackOverflow answer also really helps, as it illustrates how to define more than one channel in javascript (here with updated syntax):