I came from a game development background and have little experience with web servers.
I'm developing a web server based on Elixir/Phoenix. Say we have some players that can join guilds. The relationship between Guild
and Player
is one-to-many. In order to boost up the performance, we want to cache data in memory as much as possible, so we cache data of players and also guilds. But since players may "share" the same guilds, we attempt to wrap the guild data into a GenServer, so that every operation for a single guild can be performed sequentially.
With the design mentioned above, we realized that caching for the guild became a little bit tricky to deal with. Since every guild itself is a separate process, what process is in charge of expiring the guild process?
- If the guild process is in charge of expiring itself, every cast/call message sent after the expiration could not be successfully run.
- If we have a
GuildManager
to manage all the expiration logic for the guild processes. Kill a guild process would also cause every guild-pid-holder process to crash.
So what's the best practice to deal with this kind of problem?
question from:https://stackoverflow.com/questions/65661196/elixir-best-practice-to-wrap-a-timed-state-inside-a-genserver