How it works
A session is what the server remembers about a logged-in user between requests. If a session exists only on one web server, a later request sent to another server may appear logged out. Sticky sessions route a user back to the same server, but they make server removal and failure recovery harder: a rolling deploy that restarts each server logs all those users out.
There are two common ways out. The first is a shared store: move session information into Redis or a database that all web servers can reach, and give the browser only a random session ID. Each request costs a lookup, typically about a millisecond on the same network, and the store needs its own availability plan. In exchange, deleting a record logs someone out at once.
The second is a signed token, such as a JSON Web Token (JWT). At login, the server signs a small document containing the user ID and an expiry, and the client sends it with each request. Any server holding the verification key can check it without a lookup. The cost is revocation: a token stays valid until it expires unless you add a server-side deny list, which brings back a lookup. Teams often pair expiries of minutes with a refresh step. Standard JWT payloads are readable, so they should not hold secrets.
Either way, the web tier is stateless with respect to sessions: servers can be added or removed without moving anyone’s session. The system still has state; it simply lives outside the web process.
A login works on Server A, then fails when the next request lands on Server B.
Move session state to a shared store, or issue signed tokens, so either server can authenticate the next request. This makes servers replaceable, but a shared store needs its own availability and capacity plan, and signed tokens are hard to revoke before they expire.
Use this as a guide for self review; written answers are not graded.Keep in mind
- Stateless web servers do not keep unique user sessions locally.
- A shared store makes revocation easy; signed tokens avoid the lookup but are hard to revoke early.