Tomcat supports session replication across a cluster of nodes usingDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/apache/tomcat/llms.txt
Use this file to discover all available pages before exploring further.
SimpleTcpCluster. When a user’s session data is replicated to other nodes, any member of the cluster can service subsequent requests without data loss if the original node fails. Clustered deployments require that all session attributes implement java.io.Serializable, a load balancer in front of the cluster (such as Apache HTTP Server with mod_jk or mod_proxy_balancer), and a consistent application deployment across every node in the cluster.
Requirements
Before enabling clustering, verify that your environment meets the following prerequisites:Serializable Session Attributes
Every object stored in
HttpSession — directly or transitively — must implement java.io.Serializable. Non-serializable attributes will cause replication to fail with a serialization exception at runtime.Consistent Application Deployment
The same version of your web application must be deployed at the same context path on every cluster node. Session data is replicated as binary-serialized Java objects; class mismatches between nodes will produce
ClassNotFoundException or InvalidClassException.Load Balancer with Sticky Sessions
A load balancer should be configured to route subsequent requests from the same client to the same Tomcat node (sticky sessions). Set the
jvmRoute attribute on the <Engine> element so the load balancer can identify which node owns a session from the session ID itself.Basic Cluster Configuration
The minimal cluster configuration is a single line inside the<Engine> element in conf/server.xml:
- Session Manager:
DeltaManager(full session delta replication to all nodes) - Membership:
McastServiceusing multicast group228.0.0.4:45564 - Receiver:
NioReceiverlistening onauto(first available port in the range4000–4100) - Sender:
ReplicationTransmitterwithPooledParallelSender
SimpleTcpCluster
SimpleTcpCluster (org.apache.catalina.ha.tcp.SimpleTcpCluster) is the primary clustering implementation. It orchestrates the Channel (the underlying communication fabric), the session manager, and cluster-aware valves.
A fully expanded configuration with explicit sub-components looks like this:
SimpleTcpCluster attributes:
| Attribute | Default | Description |
|---|---|---|
channelSendOptions | 8 | Bit-field controlling message delivery guarantees. 8 = SEND_OPTIONS_ASYNCHRONOUS (message placed on a queue and sent by a separate thread) |
channelStartOptions | 15 | Which Channel services to start (bitmask; 15 = all) |
heartbeatBackgroundEnabled | false | Run Channel.heartbeat() in the container background thread |
Session Managers
DeltaManager (Default)
DeltaManager replicates session deltas — only the attributes changed during a request — to all other cluster nodes. Every node maintains a complete copy of every session in the cluster.
| Attribute | Default | Description |
|---|---|---|
expireSessionsOnShutdown | false | Expire all sessions when the node shuts down (instead of replicating the shutdown) |
notifyListenersOnReplication | true | Fire HttpSessionAttributeListener events on replication receipt |
stateTransferTimeout | 60 | Seconds to wait for full state transfer when joining the cluster |
BackupManager
BackupManager replicates each session to exactly one backup node (chosen consistently by hashing the session ID). This dramatically reduces network traffic in large clusters because only one other node receives each session’s data.
| Attribute | Default | Description |
|---|---|---|
mapSendOptions | 6 | Delivery options for the distributed map used to locate session backups |
DeltaManager.
BackupManager requires that the load balancer support session-aware routing or sticky sessions. If a request arrives at a node that is neither the primary nor the backup for that session, an additional network hop is required to retrieve the session. This is transparent to the application but adds latency.Membership: Multicast vs. Static
Multicast Membership (Default)
McastService uses UDP multicast for automatic node discovery. Nodes broadcast their presence to the configured multicast group and listen for other nodes’ announcements.
| Attribute | Default | Description |
|---|---|---|
address | 228.0.0.4 | Multicast group IP address |
port | 45564 | Multicast port |
frequency | 500 | How often (ms) to send membership heartbeats |
dropTime | 3000 | Milliseconds without a heartbeat before a member is considered dead |
Static Membership
When multicast is unavailable, replaceMcastService with StaticMembershipService and enumerate cluster nodes explicitly using StaticMembershipInterceptor:
StaticMember requires a uniqueId that is globally unique within the cluster — use distinct byte values in the last position for each node.
jvmRoute for Load Balancer Affinity
ThejvmRoute attribute on the <Engine> element causes Tomcat to append a node identifier to every session ID it creates. For example, if jvmRoute="jvm1", a session ID might look like B7C3A9D1E2F4.jvm1.
. to determine which node owns the session and routes subsequent requests there. Each node in the cluster must have a unique jvmRoute value.
In Apache HTTP Server with mod_proxy_balancer:
Web Application Clustering Support
A web application must explicitly opt in to session replication by declaring itself distributable inWEB-INF/web.xml:
<distributable/>, Tomcat uses a non-replicated session manager even when a <Cluster> is configured.
Session attribute requirements:
- All session attributes must implement
java.io.Serializable. - Objects referenced by session attributes (transitively) must also be serializable.
transientfields will not be replicated to other nodes.
Cluster Communication Security
By default, Tomcat cluster replication messages are transmitted over unencrypted TCP. In production environments — especially where cluster traffic crosses network boundaries — you should secure the replication channel. Configure TLS on theNioReceiver and PooledParallelSender by adding SSL configuration to the channel transport. Alternatively, run cluster replication over a dedicated encrypted overlay network (e.g., WireGuard or IPsec) to keep the Tomcat configuration simple while still protecting data in transit.
For deployments on Kubernetes, running each cluster’s pod-to-pod communication inside a service mesh (e.g., Istio with mTLS) provides transparent encryption without changes to server.xml.