Almah
Using Presence to keep track of users across temporary "sessions"
I’m working on creating a workshop app that allows moderators to start a “session” of a premade workshop. Each session can have many participants and the moderator should be able to see which participants have joined and what their status is (ready, finished). I thought I’d use Presence for this but I’m unsure how to proceed because sessions and their participants need to be isolated from each other with no data leaking through. Should I:
- Create a single Presence topic with the session id as a key? I’d have to filter for the correct session per invocation, making the app slightly more error-prone and potentially slow if I ever have hundreds of concurrent sessions.
- Create a custom Presence topic whenever a workshop session is started and use that to track its participants? The presence topic would then be persisted to the DB as part of the session object.
- Something else?
Any help would be much appreciated as I’m still learning phoenix and am trying to figure out what the best practices are ![]()
First Post!
krasenyp
I think you can model your sessions as processes, be it a GenServer or gen_statem, and their lifecycle using a DynamicSupervisor and a Registry. Then, as it’s written in the docs, you can use Phoenix.Tracker as a lower level tool than Phoenix.Presence. In your tracker implementation you could call a router to route presence changes to a particular session. This way you’ll invert the direction of messages, instead of subscribing to a topic and waiting which allows anyone to subscribe to any topic, you’ll push messages to a destination.
Popular in Questions
Other popular topics
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
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









