How to keep a session consistent across Web cluster?
Sol 1: ip_hash based load balance
The load balancing strategy of nginx can be configured to ip_hash.
The basic idea is Hash(client_ip)%nodes.
Sol 1 is easy to configure and can be adopted in middle-scale distributed environment,
no changing the code.
Sol 2: session synchronization among all web servers
Tomcat server supports cluster through modifying the two configuration files below:
a. server.xml, just opening the
Sol 3: concentrated cache for sessions
Redis is used as the concentrated cache to store the sessions from all web servers.
Sol 3 is the first choice in large-scale distributed application because it is scalable and robust,
but changing the code.