title: Alternatives to session variables in Java
body: <p>I was going through some of the questions here trying to find alternatives to using session variables. I have a few points to make, so I'm posting mine as a new question. </p>
  
  <p>My web application is built on Java using springs. I use plain SQL and hibernate both to do a bunch of database read/write operations. It's running on two Tomcat containers. My requirement is to find a suitable and scalable alternative to using session variables. Currently, I am using session to store a whole lot of transactions. There are two type of transactions, completed and queued and I have two session objects to store them. There are thousands of transactions and each transaction has about 10 variables associated with it.  </p>
  
  <ol>
  <li>First I want to store all the transactions in session. Reason being I want to avoid database queries until something has changed, ie, any of the transactions has been updated. I have the logic in place to reload the sessions objects when any updates occur.   </li>
  <li>There are not many users of the web application yet so I don't have a big need to optimize memory size to store all the session objects, but it would be definitely nice to have a design which could hold hundreds of thousands of transactions.</li>
  <li>I have a load balancer and my web applications runs on two Tomcat applications and I am running into issues where the transactions loaded on different servers are mismatching. For example, I sort my transactions based on date - when I browse through different transactions they are not staying sorted on the date. I am assuming one of the servers has a sorted list and the other has an unsorted list. I haven't explored the option for session replicating, and I don't really want to use sticky session.</li>
  <li>Using cookies - too troublesome because of the big number of transactions and details of each.</li>
  <li>Using hidden variables or as request attributes - not good since I have to convert every link into a form submit.</li>
  <li>Custom caching - haven't explored and don't have a big infrastructure to implement it right now.</li>
  </ol>
  
  <p>Are there other alternatives I haven't though of?</p>