Could this be a valid use for GenServer:
If the process_id is the user_id and it is unique. Process contains a query result of a big map of data which is generated via DB. Now if 100's of users log in to the system and ask for their data map they all are saved in their own process referenced by the user_id which is unique
So upon asking for the map I will check to see if there is a process with user_id ( which is process id ) and grab it and feed it to back to the user, if not then I create it and put it in a new state
now if user updated his map, at the update, I make sure to update the sate or create a new one.
Thank you for your guidance
This is perfectly valid unless you have a million users logged in. This is usually handled in Erlang ecosystem with so-called pools.
The main principle is: you limit the size of the pool of processes to, say, 100 (5000, whatever, it mostly depends on your HW capacity) and use any preemptive storage for newcomers (the oldest dies if the capacity is over the limit.)
You might consider serializing these displaced data, or spawn new nodes, or whatever. In general, the process holding the state is the preferable solution in OTP, unless you hit the memory limit. In this case you’d probably opt-in for some persistent storage, like DETS or (better) mnesia.
It worth noting that Elixir provides Agent
module for this purpose, but I never use it because plain old good GenServer is IMHO a cleaner concept.