Solutions for Session Consistency Problem in Web Cluster
How to keep a sessionconsistent 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 <Cluster> node.b. web.xml, adding <distributable> node.Sol 2 is applied in small-scale distributed environment, no changing the code.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.