Skip to main content

Tomcat Deployment Architecture Complete Guide 2026

Published: April 24, 2016 Updated: May 25, 2026 Larry Qu 3 min read

Tomcat Deployment Architecture Overview

Tomcat deployment architectures vary by application scale and requirements, and can be divided into multiple tiers.

Architecture Tiers

1. Single Node Architecture

┌─────────────────────────┐
│      Client            │
└───────────┬─────────────┘
┌─────────────────────────┐
│     Tomcat Server      │
│  ┌─────────────────┐   │
│  │   Web App       │   │
│  └─────────────────┘   │
└─────────────────────────┘

Use cases:

  • Development/testing environments
  • Small applications
  • Single user access

Pros: Simple, quick deployment Cons: No high availability, single point of failure

2. Load Balancing Architecture

┌─────────────────────────┐
│      Client             │
└───────────┬─────────────┘
┌─────────────────────────┐
│  Nginx / HAProxy        │
│   (Load Balancer)       │
└───────────┬─────────────┘
     ┌──────┴──────┐
     ▼             ▼
┌─────────┐   ┌─────────┐
│ Tomcat 1│   │ Tomcat 2│
└─────────┘   └─────────┘

Nginx configuration example:

upstream tomcat_cluster {
    server 192.168.1.10:8080;
    server 192.168.1.11:8080;
    # Weighted configuration
    server 192.168.1.12:8080 weight=2;
}

server {
    listen 80;
    server_name example.com;
    
    location / {
        proxy_pass http://tomcat_cluster;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Use cases:

  • Medium-sized applications
  • High availability required
  • Moderate user traffic

3. Architecture with Caching

┌─────────────────────────┐
│      Client             │
└───────────┬─────────────┘
┌─────────────────────────┐
│   Nginx / HAProxy       │
└───────────┬─────────────┘
     ┌──────┴──────┐
     ▼             ▼
┌─────────┐   ┌─────────┐
│ Varnish │   │ Varnish │  (Cache Servers)
│  Cache  │   │  Cache  │
└────┬────┘   └────┬────┘
     │             │
     └──────┬──────┘
┌─────────────────────────┐
│     Tomcat Cluster      │
└─────────────────────────┘

Varnish configuration example:

vcl 4.1;

backend tomcat1 {
    .host = "192.168.1.10";
    .port = "8080";
}

sub vcl_recv {
    # Do not cache logged-in user requests
    if (req.http.Cookie) {
        return (pass);
    }
}

sub vcl_backend_response {
    # Cache static resources for 1 hour
    if (bereq.url ~ "\.(css|js|jpg|png)$") {
        set beresp.ttl = 1h;
    }
}

Use cases:

  • High-traffic websites
  • Many static resources
  • Fast response times required

4. Full Distributed Architecture

┌─────────────────────────────────────────┐
│              Client                     │
└────────────────┬────────────────────────┘
┌─────────────────────────────────────────┐
│          Nginx / HAProxy                │
│          (Load Balancer)                │
└────────────────┬────────────────────────┘
        ┌────────┴────────┐
        ▼                 ▼
┌───────────────┐   ┌───────────────┐
│  Varnish      │   │  Varnish      │
│  Cache        │   │  Cache        │
└───────┬───────┘   └───────┬───────┘
        │                   │
        └────────┬──────────┘
        ┌────────┴────────┐
        ▼                 ▼
┌───────────────┐   ┌───────────────┐
│ Tomcat 1      │   │ Tomcat 2      │
│ (Session)     │   │ (Session)     │
└───────┬───────┘   └───────┬───────┘
        │                   │
        └────────┬──────────┘
        ┌────────┴────────┐
        ▼                 ▼
┌───────────────┐   ┌───────────────┐
│ Memcached    │   │  MySQL        │
│ (Session)    │   │  (Database)   │
└───────────────┘   └───────────────┘

Session sharing configuration (Memcached):

<!-- context.xml -->
<Manager className="de.myfocus.mngr.MemcachedBackupManager"
         memcachedNodes="n1:192.168.1.20:11211,n2:192.168.1.21:11211"
         requestUriIgnorePattern=".*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$"
         sticky="false" />

Session Management Strategies

1. Sticky Session

upstream tomcat {
    ip_hash;  # Same IP goes to same Tomcat
    server 192.168.1.10:8080;
    server 192.168.1.11:8080;
}

2. Session Replication

<!-- server.xml -->
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
    <Manager className="org.apache.catalina.ha.session.DeltaManager"
             expireSessionsOnShutdown="false"
             notifyListenersOnReplication="true"/>
</Cluster>

3. External Session Storage

Use Redis or Memcached for session storage:

// Spring Session + Redis
@Configuration
@EnableRedisHttpSession
public class RedisSessionConfig {
    @Bean
    public LettuceConnectionFactory connectionFactory() {
        return new LettuceConnectionFactory();
    }
}
Scale Recommended Architecture Characteristics
Small Single node Simple and fast
Medium Nginx + Tomcat cluster High availability
Large Nginx + Varnish + Tomcat cluster + Memcached High performance
Extra large K8s + Microservices Elastic scaling

Performance Optimization Tips

  1. JVM tuning

    CATALINA_OPTS="-Xms512m -Xmx2048m -XX:+UseG1GC"
    
  2. Connection pool configuration

    <Resource name="jdbc/mydb" 
              maxTotal="100" 
              maxIdle="30" 
              maxWaitMillis="10000"/>
    
  3. Enable compression

    gzip on;
    gzip_types text/plain text/css application/json application/javascript;
    

Comments

👍 Was this article helpful?