How Flask-login works with multiple servers

I used the flash registration module , which creates and maintains a session on the server.

Since the server supports the session, I think that it is not completely stateless. How it works when an application has more than one server. If the requests should be sticky (that is, the given session should perform subsequent requests to a specific server)?

+6
source share
1 answer

This expression you made is not entirely correct:

... which creates and maintains a session on the server.

Flask-Login uses the session facilities provided by Flask, so the data stored in it is recorded by Flask using the configured session storage engine.

By default, Flask records user sessions as secure cookies in the client, but a session on the server is also possible. For example, this snippet shows how to configure Flask to record sessions in Redis server storage.

When a user session is stored in a cookie on the client side, it is pretty obvious that having multiple servers is not a problem. Cookies will be sent to the server processing each request, so everything will work fine.

For server side sessions, this also works. A server-side session is recorded under a unique identifier, and this unique identifier is then stored in a cookie on the client side. Each request then contains a session identifier, and Flask uses this identifier to load session data. If you configure all web servers to use the same user session repository, several servers can process requests from the same client without problems.

+10
source

Source: https://habr.com/ru/post/954903/


All Articles