If you do not want to use the session as intended, it should be used, then do not use it at all - create your own session object. It can still implement HttpSession and even extend from the implementation of HttpSession .
You can use Filter to transfer your request so that it returns a session object, not a standard one. In your session, you can store things in the database, not in memory.
Instead of writing to the database, you can use Hazelcast - it provides distributed collections. But I think it will take as much effort as setting up session replication. Session replication is not difficult — it is supported by all containers.
These are rough recommendations; the task will not be trivial. And I would recommend sticking to standard session usage patterns and storing things in the database only if necessary.
To avoid the need for replication, you can try using sticky sessions — that is, when a user is redirected to a server using a load balancer, each subsequent request from that user is sent to the same server.
Bozho Jan 31 2018-11-21T00: 00Z
source share