Hi there,
I am currently developing an application using Phoenix LiveView. This application is meant to generate a visualization of something. A visualization that is global/shared, which in turn requires a server-side global/shared state. I would prefer to not use a database at this moment in time, as I do not need the persistence and I fear it might be too slow on a large scale. More concretely, my requirements are as follows:
- When I start the (web)application, a default (shared) state should be generated and kept in memory. I would prefer to not use databases at this moment.
- When a user connects to the (web)application and thus sets up a liveview session, the shared state should be fetched and used.
- The shared state can be updated via API calls made to the server.
- Whenever the shared state changes, all connected users should receive a notification of this fact.
- No persisted database is used.
I currently tried Phoenix LiveSession to achieve this goal, but as the name suggests this only seems to keep a server-side session state. It is not a global state with which all users can interact as described in the requirements above. Another solution I read and thought about was using a GenServer
, but I couldn’t seem to find a good explaination on how to concretely do this in LiveView. Combined with the fact I am pretty new to all of this makes me pretty lost in regards to that option. As for other solutions, I mainly seem to come across solutions that make use of a persisted database.
Hopefully someone here can put me on the right track!
Small note: I am pretty new to Elixir