title: rails turn based game manager
body: <p>I am writing a turn based card game (line an online poker). I have experience using rails so i would like to use it for the majority of the logic like managing the users with coins and statistics, manage rooms and games. I am planning to use node js + socket.io + redis to provide realtime messaging server -> client (basically use redis from rails to publish messages, listen to them on node.js side and publish through socket.io to the clients) and using REST API to communicate from the client -> server.</p>
  
  <p>The part i am stuck on is trying to manage the actual game logic inside rails. I would need a Game Manager for each game in progress which would evaluate everything that happens in a game (dealing cards, accepting bets, going through player turns, evaluating results etc..). Two things in particular seems kinda impossible to me and that is this situation from my experience building webapps with rails so far:</p>
  
  <ul>
  <li><p>Having the game manager as a single shared object in memory:
  I was thinking this could be a redis cached object and will be reloaded on each state change and saved again with the new state which seems like a big overhead. 
  Another thing i was considering was holding a hash of game manager objects, one for each ongoing game as a static object accessible from anywhere in the rails app. Anything i am missing here? Can this be somehow improved or any other approach to doing this sort of a functionality?</p></li>
  <li><p>Having a timer that ticks while waiting for a player to make a move
  Like any turn based game i would need to wait a specific number of seconds until a player reacts, if the player doesn't take action in lets say 20 seconds then the server should automatically move to the next player.
  I really don't know how to do this in rails. One approach i was considering was a delayed task which will run after 20 seconds and expire the players turn or be canceled if the user acts before it. (using sidekiq for example for these tasks).</p></li>
  </ul>
  
  <p><strong>EDIT</strong> </p>
  
  <p>I am stuck on designing how to implement the actual game logic, thats why i need a game manager, there needs to be a timer ticking every 1 second for every active game (game that has at least 2 players), there needs to be a callback after x seconds if a player doesn't take their turn to move to the next player. I don't see how i can do that in rails due to the stateless nature of each request and i need to store game state in memory and run a timer somehow.
  I do believe i can solve this specific issue around game logic in node.js, but i would rather use node.js just to manage the socket connections and receive events through redis pub/sub.</p>