I have a setup of several Tomcat servers distributed between a few servers, all running the same thing. Apache is on top of Apache and a loadbalancer in front of the Apache servers. I want to cluster the Tomcats using Shared Session to minimize downtime and user interruption while deploying apps.

I know clustering works within the same server but is it possible to setup Tomcat in a way that it shares sessions between servers on different machines?

=> Server 1
==> Apache 1
===> Tomcat 1

=> Server 2
==> Apache 2
===> Tomcat 2

When Server/Tomcat 1 would be taken down, users and their sessions would transfer over to Server/Tomcat 2 and vice versa.

  • Apache is on top of Apache? – mr.zog May 5 '16 at 0:14

Take a look at Teracotta for web sessions.

Use Terracotta's fast, reliable web sessions plugin to get the scalability benefits of a stateless web architecture without overloading your database or rewriting your application. Terracotta for Sessions works with your favorite web framework and your own custom session objects.

The web sessions tutorial lists five simple steps for you to make in order to evaluate the product ( FOSS ).

  • 1
    Last time I looked.. Terracotta was damn expensive.. At least memcached is free. – Tom O'Connor Aug 1 '10 at 22:55
  • @Tom : as stated in my answer, there is a FOSS version of Teracotta. If that does not suite your needs, you might want to look into the commercial version. But it's not mandatory. – Robert Munteanu Aug 2 '10 at 20:28
  • I've looked into Terracotta before, Last time, the FOSS version didn't have the required product. – Tom O'Connor Aug 2 '10 at 22:03

I am working on setting up the same thing, the below link from Apache gives on overview of how to achieve this :


There are basically two parts to this :

1) Making your session objects serializable

2) Setting up the clustering config in tomcat (server.xml).

Depending on which tomcat manager you use, you may have to enable multicast on your nodes, to enable communication between the nodes. The session replication is handled by tomcat via these multicast pings.I have seen many people using this approach, and it has worked for them (Seems to be a standard/simple way of doing it).

Also here is a detailed blog post about the same - there are 5 parts, with some videos.


P.S :

I am using the same approach, for the the same problem with 2 tomcat nodes. I am facing a small issue, which is documented below, if you do succeed/run into similar issue, please have a look at this

Tomcat session replication issue


You can save sessions in database, so they are accesible from both tomcats. Or store them over a shared directory between tomcats.


You can save sessions in memcached, which is shared between both servers. This should give better performance and scalability than using shared sessions in a database, or a shared directory between n servers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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