<p>Tomcat (version 5 here) stores session information in memory. When clustering this information is periodically broadcast to other servers in the cluster to keep things in sync. You can use a database store to make sessions persistant but this information is only written periodically as well and is only really used for failure-recovery rather than actually replacing the in-memory sessions.</p>

<p>If you don't want to use sticky sessions (our configuration doesn't allow it unfortunately) this raises the problem of the sessions getting out of sync.</p>

<p>In other languages, web frameworks tend to allow you to use a database as the primary session store. Whilst this introduces a potential scaling issue it does make session management very straightforward. I'm wondering if there's a way to get tomcat to use a database for sessions in this way (technically this would also remove the need for any clustering configuration in the tomcat server.xml).</p>

[{'answer_id': 82384, 'author': 'Joe Skora', 'author_id': 14057, 'author_profile': 'https://Stackoverflow.com/users/14057', 'pm_score': 2, 'selected': False, 'text': '<p>Take a look at <a href="http://www.terracotta.org/" rel="nofollow noreferrer">Terracotta</a>, I think it can address your scaling issues without a major application redesign.</p>\n'}, {'answer_id': 82392, 'author': 'Olaf Kock', 'author_id': 13447, 'author_profile': 'https://Stackoverflow.com/users/13447', 'pm_score': 3, 'selected': True, 'text': '<p>There definitely is a way. Though I\'d strongly vote for sticky sessions - saves so much load for your servers/database (unless something fails)...</p>\n\n<p><a href="http://tomcat.apache.org/tomcat-5.5-doc/config/manager.html" rel="nofollow noreferrer">http://tomcat.apache.org/tomcat-5.5-doc/config/manager.html</a> has information about SessionManager configuration and setup for Tomcat. Depending on your exact requirements you might have to implement your own session manager, but this starting point should provide some help.</p>\n'}, {'answer_id': 3358787, 'author': 'Chris', 'author_id': 59198, 'author_profile': 'https://Stackoverflow.com/users/59198', 'pm_score': 2, 'selected': False, 'text': "<p>I've always been a fan of the Rails sessions technique: store the sessions (zipped+encrypted+signed) in the user's cookie. That way you can do load balancing to your hearts content, and not have to worry about sticky sessions, or hitting the database for your session data, etc. I'm just not sure you could implement that easily in a java app without some sort of rewriting of your session-access code. Anyway just a thought.</p>\n"}, {'answer_id': 5632298, 'author': 'MartinGrotzke', 'author_id': 130167, 'author_profile': 'https://Stackoverflow.com/users/130167', 'pm_score': 2, 'selected': False, 'text': '<p>Another alternative would be the <a href="http://code.google.com/p/memcached-session-manager/" rel="nofollow">memcached-session-manager</a>, a memcached based session failover and session replication solution for tomcat 6.x / 7.x. It supports both sticky sessions and non-sticky sessions.</p>\n\n<p>I created this project to get the best of performance and reliability and to be able to scale out by just adding more tomcat and memcached nodes.</p>\n'}]
['https://Stackoverflow.com/questions/82340', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/15687/']