Hello everyone! I watched the following talk at elixir conf 2018 OTP and docker my question is assuming we would like to create a statefull woordle game… and keep the scores of each player how would it scale? Can we just insert a ‘‘key’’ to the genserver for each new user or eventually will it “explode” and reach its limit? What would be a nice solution to keep all game state inside the application without a database
OTP docker and its limitations - is there a way to keep all game state inside the application without a database?
If you keep increasing the size of the state of a GenServer process you will eventually run out of memory.
Databases are unique beasts that store data in a blend of disk and memory (indexes).
So if you find yourself having to store absurd amounts of data then I’d look at a database.
Alternately, you might be able to come up with some sharding solution to partition the key space across multiple genservers. In which case, I’d also look at something like a Cassandra.
I wouldn’t worry too much about size, storing a pair of user ID and score would only be a few bytes, you’d have to have an extraordinary number of users for that to add up to a meaningful amount of memory!
I think persistence is probably the more interesting question. Presumably you want to store the game state so it persists across restarts.
Have you thought about SQLite? It’s pretty easy to use and it stores the database in a file, you don’t have to run a database server for example, it sounds like it might be a good fit at this stage. You could mount a volume in your docker container so the file gets saved on disk.
You could also look at dets but it comes with some limitations IIRC, truthfully if it were me I’d use SQLite.
If you don’t care about persistence you could check out ETS tables, but I’m guessing you want scores to stick around!
Just use CubDB:
You could also consider mnesia.