WebSphere Tutorial · Traditional WebSphere Application Server · Lesson 16 of 23

Sessions and High Availability

Keeping HTTP sessions through failures with memory-to-memory replication or database persistence, and designing stateless instead.

Members can save this page, take notes and track progress. See membership · Sign in

Where sessions live

By default a session lives only in one cluster member's memory. When that member fails or restarts, its users lose their sessions (shopping carts, logins). Options:

Option How Trade-off
Memory-to-memory replication Members copy sessions to each other Extra memory and network; fast failover
Database persistence Sessions written to a database table Survives full restarts; adds database load and latency
Liberty session cache sessionCache feature with a JCache provider (Hazelcast, Infinispan) External cache to run
Stateless design Tokens or an external store; no server sessions Best for containers; needs application changes

Keep sessions small and serialisable: a few kilobytes, not whole result sets. The default timeout is 30 minutes.

Why session size matters for replicationTry it yourself
users = 20_000
for kb in [2, 50, 500]:
    total_mb = users * kb / 1024
    replicated = total_mb * 2
    print(f"{kb:4} KB per session x {users:,} users = {total_mb:8,.0f} MB in memory, "
          f"{replicated:8,.0f} MB with one replica")

Output

   2 KB per session x 20,000 users =       39 MB in memory,       78 MB with one replica
  50 KB per session x 20,000 users =      977 MB in memory,    1,953 MB with one replica
 500 KB per session x 20,000 users =    9,766 MB in memory,   19,531 MB with one replica

Test yourself

A member crashes and its users are logged out. What would have prevented it?

  1. A bigger heap
  2. Session replication or persistence (or a stateless design)
  3. Parent-last class loading
  4. More plug-in weights
Show answer

Answer: Session replication or persistence (or a stateless design)

Sessions only in one member's memory die with it.

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake