Hi! I have a doubt about WebApp User session, lets say that I have a web app running in two servers and I have a load balancer that distributes the traffic depending on the load, in this scheme could happen that a user makes a request and the load balancer send the user to server 1, but when this user makes another request, the seccond request could go to server 2 (because there is less load, or server 1 is not available) my question is how can we manage the user session between the two servers?
I'm asking because currently I'm learning about kubernetes and this kind of things happend frequently and I was thinking about B4J webapps in this environment, and also, this is something that you have to solve if you need horizontal scaling for your app.
This should be done with sticky sessions by your load balancer I think. Could be a cookie injected by the load balancer so once you are redirected to a server, it should always go to this server for this session.
Hi @alwaysbusy thanks for your reply!, you are rigth it could be done with sticky sessions, the only con that I can see is that sticky sessions also make it more difficult to keep servers in balance. A server can become overloaded if it accumulates too many sessions, or if specific sticky sessions require a high number of resources. This could result in your load balancer having to shift a client to a different server mid-session, resulting in data loss.
As far as I understand, B4J webserver will create a cookie for the new user where it saves the session data, it could be possible to read this cookie if the client is shifted to a different server?
yes, probably it's not possible, I was thinking in some alternatives like creating handlers to share the data or send requests like with microservices but, all the "solutions" that I think seems to be too complex, finding a way to share or reuse the cookie would be great.
Session tracking enables you to track a user's progress over multiple servlets or HTML pages, which, by nature, are stateless. A session is defined as a series of related browser requests that come from the same client during a certain time period. Session tracking ties together a series of browser requests think of these requests as pages that may have some meaning as a whole, such as a shopping cart application. For more detail also see https://www.b4x.com/android/forum/threads/web-app-sessions-with-bik-two-servers.140065/
I think that you will be able to read the cookies. You will definitely be able to do it with a reverse proxy solution.
With that said, a single B4J server can handle many concurrent solution. If you really need to add a load balancer then sticky sessions should be enough to solve the load.
No need to do anything special. The request will include the cookies, assuming that the proxy is configured to pass the cookies. ServletRequest.GetCookies.