Tomcat
session replication
DeltaManager
BackupManager
web application management

Tomcat 8 DeltaManager vs BackupManager session replication

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Apache Tomcat is a popular open-source Java Servlet Container developed by the Apache Software Foundation. It supports the deployment of Java-based applications and is widely used for its flexibility and reliability. When running Tomcat in a cluster environment, session replication is crucial for providing high availability and ensuring that user sessions are maintained across multiple nodes. Two primary options for session replication in Tomcat 8 are DeltaManager and BackupManager. Each has its own mechanisms and trade-offs, so it's essential to understand how they work to choose the right approach for your needs.

DeltaManager vs BackupManager

DeltaManager and BackupManager are both managers provided by Apache Tomcat for session replication, but they operate in different ways:

DeltaManager

DeltaManager replicates session data across all nodes in the cluster. When a change is made to a session on one node, only the deltas (or changes) of that session are propagated to the other nodes. This approach ensures that each node has an up-to-date copy of every session, which provides redundancy and high availability.

Technical Explanation

  • Replication Method: Full and Incremental
    • Performs both full and incremental replication, which might lead to higher network traffic, especially in large clusters.
  • State Consistency: Strong consistency
    • Since all sessions are replicated everywhere, if any node fails, another node can continue processing without missing any data.
  • Use Cases: Suitable for small to medium-sized clusters where maintaining consistent session states is critical.

Example

Imagine a cluster with three nodes: A, B, and C. If a session attribute is modified on node A, DeltaManager only sends the change (not the entire session) to nodes B and C. This way, nodes B and C have the updated session without needing the full session data, minimizing data transfer while ensuring synchronization.

BackupManager

BackupManager, on the other hand, maintains a primary-backup strategy. Each session is replicated to one or multiple backup nodes rather than every node. This approach reduces the overhead of replication because not every node receives every session's data.

Technical Explanation

  • Replication Method: Primary-Backup
    • Each session has a primary home node and backup nodes, which means less network traffic and storage overhead compared to DeltaManager.
  • State Consistency: Eventual consistency
    • While the network traffic issue is mitigated, there is a slight lag between the primary and backup nodes, which can lead to eventual consistency.
  • Use Cases: Preferable for large clusters where reducing replication traffic is essential.

Example

Consider a cluster with nodes X, Y, and Z. A session created on node X has node Y as a backup. If node X fails, node Y takes over the session handling, maintaining availability with reduced network usage.

Key Differences: DeltaManager vs BackupManager

Here's a concise comparison of the two session replication strategies:

FeatureDeltaManagerBackupManager
Replication MethodFull and IncrementalPrimary-Backup
State ConsistencyStrongEventual
Network TrafficHigh (all nodes receive changes)Moderate (only backup nodes receive)
FailoverImmediate, seamlessSlight delay due to eventual syncing
Cluster SuitabilitySmall to MediumLarge
ScalabilityLimited by network constraintsBetter scalability for larger clusters

Additional Considerations

Session Persistence

Regardless of whether DeltaManager or BackupManager is used, configuring session persistence is crucial for data integrity during restarts. Tomcat supports persistent sessions by writing them to a persistent storage like a database or file system, so sessions can be restored on a node restart.

xml
1<Manager className="org.apache.catalina.session.PersistentManager" 
2         maxIdleSwap="60" 
3         saveOnRestart="true">
4    <Store className="org.apache.catalina.session.FileStore" 
5           directory="webapps/yourapp/sessions"/>
6</Manager>

Security

Session replication raises security concerns, such as session hijacking and replication of sensitive data. Ensure encryption and secure communication channels (e.g., using TLS) between replicated nodes to protect session data.

Performance Tuning

For efficient session replication, tune network settings, JVM parameters, and Tomcat configurations to balance performance and resource usage. Specifically, adjust the session timeout settings and compression options to optimize data transfer.

In conclusion, choosing between DeltaManager and BackupManager depends on the specific needs of your application and cluster size. For smaller clusters requiring consistency, DeltaManager is advantageous, whereas, for extensive installations, BackupManager offers a scalable solution with reduced overhead. Understanding the trade-offs between these two options allows you to configure Tomcat's session replication according to your application's requirements.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.