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:

  1. 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.
  2. 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.
  3. 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 :slight_smile:

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.