title: Azure Websites and stateful webApp
body: <p>I have a naïve version of a PokerApp running as an Azure Website. </p>
  
  <p>The server stores in its memory the state of the tables, (whose turn it is, blinds value, cards…) etc.</p>
  
  <p>The problem here is that I don't know how much I can rely on the WebServer's memory to be "permanent". A simple restart of the server would cause that memory to be lost and therefore all the games in progress before the restart would get lost / cause trouble.</p>
  
  <p>I've read about using TableStorage to keep session data and share it between instances, but in my case it's not just string of text that I want to share but let's say for example, a Lobby objcet which contains all info associated with the games.</p>
  
  <hr>
  
  <p>This is very roughly the structure of the object I have in memory</p>
  
  <p><img src="https://i.stack.imgur.com/To52l.png" alt="enter image description here"></p>
  
  <hr>
  
  <p>After some of your comments, you can see the object that needs to be stored is quite big and is being almost constantly. I don't know how well serializing and deserializing is going to work for me here...</p>
  
  <p>Should I consider an azure VM which I'm hoping is going to have persistent memory instead of a Website? 
  Or is there a better approach to achieve something like this?</p>
  
  <hr>
  
  <p>Thanks all for the answers and comments, you've made it clear that one can't rely on local memory when working on the cloud. 
  I'm going to do some refactoring and optimize the "state" object and then use a caching service.</p>
  
  <p>Two question come to my mind though, and once you throw some light on these ones I promise I will shut up and accept @astaykov's great answer.</p>
  
  <p>CONCURRENCY AT INSTANCE LEVEL - I have classic thread locks in my app to avoid concurrency problems, so I'm hoping there is something equivalent for those caching services you guys propose? </p>
  
  <p>Also, I have a few timeouts per table (increase blinds, number of seconds the players have to act…). Let's say a user has just folded a hand, he's finished interacting with the state object so I update the cache. While that state object (to which the timers belong) is cached, my timers will stop ticking…<br>
  I know I'm not explaining myself very well here but I hope you guys see my point.</p>