I'm building a server for a turn-based mobile game. I'm using SignalR for communication and I was wondering if storing list of users in the memory is a good idea?

Like.. a static object of "Server" class which has List<User> same for current games. The game is pretty simple - like tic-tac-toe.

Are there better ways?

1 Answer 1


Storing transient data in memory only is OK. But there are two possible problems:

  • You can only ever use a single server process, which prevents horizontal scaling.

  • The data is lost when your server restarts.

For persistent data that should survive crashes and restarts, and for data that should be shared between server processes, you will need to store that data in some kind of database.

Whether your data should be transient or persistent depends very much on your context and the kind of data. Keeping the data in memory might be OK for a short-lived, real-time match. Perhaps session information could be stored in memory as well. But long-term statistics or login information for your user accounts need to be persisted.

  • Well, I don't think it's a "long-term" data. You can a tic-tac-toe game, ale you have to pair with opponent. So, that's only that. List of current (online) users waiting for an opponent OR currently playing. Current playing games as well (to persist connection between users that are currently in play). I think memory should be good, but when server crushes all current online games will be crushed as well. What would you do in this scenario? Are server crushes that often? Is it worth it to use database?
    – Ish Thomas
    Commented Jun 24, 2017 at 14:38
  • @IshThomas This is something you have to decide while taking the expectations of your users into account. It is uncommon that a server becomes unavailable, but you should consider the possibility when designing your system. It is OK to decide that all data is transient, and if a server fails then users log in again and start a new game. If you decide to store all games in a DB so that users can pause and continue whenever they like, that is OK as well. So this can be argued either way, but you end up with a very different user experience. In the end, what matters is that you make a decision.
    – amon
    Commented Jun 24, 2017 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.