java - How to manage sessions in a distributed application -


i have java web application deployed on 2 vms. , nlb (network load balancing) set these vms. application uses sessions. confused how user session managed in both vms. i.e. example- if make request goes vm1 , create user session. second time make request , goes vm2 , want access session data. how find session has been created in vm1.

please me clear confusion.

there several solutions:

  • configure load balancer sticky: i.e. requests belonging same session go same vm. advantage solution simple. disadvantage if 1 vm fails, half of users lose session
  • configure servers use persistent sessions. if sessions saved central database , loaded central database, both vms see same data in session. might still want have sticky sessions avoid concurrent accesses same session
  • configure servers in cluster, , distribute/replicate sessions on nodes of cluster
  • avoid using sessions, , use signed cookie identify users (and possibly contain few additional information). json web token solution. else database when need it. ensures scalability , failover, and, imo, makes things simpler on server instead of making more complicated.

you'll have in documentation of server see possible server, or use third-party solution.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -