Answer the question
In order to leave comments, you need to log in
Postgresql or redis for data used on sockets?
Hello.
For a browser game in php, sockets implemented in node.js will be used. Sockets are used for maps where players interact. Players constantly send data about their actions, we check the data on the server and send a response to the player, and in the case when he changed his coordinates, we send data about this to all other players (on their client this player is displayed at new coordinates). Accordingly, when processing requests, we constantly use and update data. The question is how best to organize their storage ?
Immediately store in postgresql and, with each request from each player, take data from there and, in fact, store it there OR store it in redisand take it from there with each request, and if there is no necessary data in redis, then take it from postgresql, and, of course, periodically save all data from redis to postgresql.
Postgresql will cope with such a load?
It is clear that it is still important to optimize the code, but now the task is to decide what to use - postgresql or redis?
Answer the question
In order to leave comments, you need to log in
In general, if the data allows them to be cached, and not to touch the database every time, it is better to cache it. More specifically, the system architect should decide, based on the specifics of the project.
Look towards tarantool - it stores data in RAM and has very fast writes + it can store more complex data than just kv.
But it’s also worth thinking about not saving data to the database for every sneeze, but for example, during the game, store them in the server’s RAM, and when the player is disconnected, already save the last coordinates in the database.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question