Quick revision
The short answer
I would ask what measured problem the change solves, because the claimed benefits mostly do not hold. A stateless JWT session cannot be logged out, revoked or updated when permissions change without adding server state back, and a cookie-based JWT still needs CSRF protection and must fit in about 4 KB. Spring Session with Redis already lets server sessions scale across instances, so unless there is a measured session-store problem, I would recommend keeping sessions.
What to remember
In this answer, we reviewed a proposal to replace server sessions with JWT cookies. The stateless benefit disappears once logout, revocation or permission changes are needed, the speed claim needs measurement, and the cookie still needs CSRF protection and must stay under about 4 KB. Spring Session with Redis already scales sessions across instances, so without a measured problem, keeping sessions is the better recommendation.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would ask what measured problem the change solves, because the claimed benefits mostly do not hold. A stateless JWT session cannot be logged out, revoked or updated when permissions change without adding server state back, and a cookie-based JWT still needs CSRF protection and must fit in about 4 KB. Spring Session with Redis already lets server sessions scale across instances, so unless there is a measured session-store problem, I would recommend keeping sessions.
Why this question is asked
Replacing sessions with JWTs is a proposal many teams make at some point, usually after reading that JWTs are stateless and therefore scale better. For a server-rendered application, where the browser talks to one backend that renders pages, the trade-offs look very different from an API serving many clients. Interviewers ask this as a review scenario to see whether we can weigh a popular idea against the specific system instead of accepting or rejecting it on reputation. In this answer, we will recap what each approach stores, check the two claims (stateless and faster), go through what the JWT version loses, compare it with Spring Session in Redis, and decide what to recommend.
1A Quick Recap of the Two Approaches
With a server session, the browser holds only a random session id in a cookie, such as SESSION=a81f.... The server keeps the session data, the logged-in user, their authorities and anything else, in memory or in a shared store. Each request looks the data up by the id. Logging out or revoking a session means deleting that data.
With a JWT session, the browser holds a signed token in a cookie that contains the data itself: the user id, roles, expiry. The server verifies the signature on each request and trusts the contents, with nothing stored on the server. That is what "stateless" means here.
2Checking the Claims: Stateless and Faster
Stateless is true only as long as we never need to change a session before it expires. The moment we want logout to work properly, or an administrator to disable a user, or a password change to end other sessions, we need state on the server again: a deny list of revoked tokens, or a version number per user, checked on every request. That brings back a lookup on each request, which is what the change was meant to remove.
Faster also needs evidence. A session lookup in Redis typically takes well under a millisecond on the same network. Verifying an RSA signature costs CPU time too, and the request now carries a cookie of 1 to 2 KB instead of 40 bytes, on every request including those for images and CSS on the same domain. For a server-rendered page that already runs database queries, the difference is usually lost in the noise. If the team has a measurement showing the session store is a bottleneck, that changes the discussion; if not, the claim is a guess.
3What the JWT Session Loses
Logout and revocation become weak. Deleting the cookie in the user's browser does not invalidate the token; a copy stolen earlier keeps working until exp. To fix that, we add a deny list, which is server state again.
Permission changes take effect slowly. The roles are inside the token, so if an administrator removes a user's admin role, the user keeps it until the token is reissued. With a session, we update or delete the session and the change applies on the next request.
CSRF protection is still needed. The JWT is in a cookie, and the browser sends cookies with cross-site requests just as it does a session cookie. So the forms still need CSRF tokens, and SameSite settings still matter. Some proposals miss this because CSRF is often discussed as a session problem.
Size is limited. Browsers allow about 4 KB per cookie, and every claim we add, such as a list of roles or tenant data, grows the token. Large tokens either get split across cookies or hit the limit and fail in ways that are hard to debug.
| Concern | Spring Session (Redis) | JWT in cookie |
|---|---|---|
| Logout / revoke | Delete the session, immediate | Needs a deny list (state again) |
| Role change | Next request | After token reissue |
| CSRF | Needed (cookie) | Still needed (cookie) |
| Cookie size | About 40 bytes | 1 to 4 KB, hard limit |
| Scale-out | Shared store, any instance | Any instance |
| Per-request cost | Sub-millisecond lookup | Signature check, larger request |
4Sessions Already Scale with Spring Session
The usual reason for wanting statelessness is horizontal scaling: with sessions in memory, a user is tied to one instance, and a restart logs everyone out. Spring Session solves that without changing the application code. It stores the HttpSession in Redis (or a database), so any instance can serve any request and restarts lose nothing.
Notice that nothing in the controllers changes, and logout, session timeout and "sign out everywhere" keep working because the data is on the server. Spring Session can also index sessions by user name, which makes ending all of a user's sessions after a password change a single call. Check the exact module and property names for your Spring Boot version.
5What I Would Recommend
My review would accept the goal, scaling and resilience, and question the means. Unless the team can show a measured problem with the session store, such as latency or cost at their traffic, I would recommend keeping server sessions and moving them to Spring Session with Redis if they are still in memory. That gives multi-instance scaling, keeps instant logout and permission changes, and avoids a migration with real security risks.
If there is a genuine need for tokens, for example the same backend must also serve mobile apps or third-party API clients, the better design keeps sessions for the browser and issues access tokens to those other clients through an OAuth2 authorization server. JWTs are good at stateless verification between services; they are a poor replacement for a browser session on a server-rendered site.
6Follow-up questions
Could short-lived JWT cookies with a refresh step fix the revocation problem?
They narrow the window, but now we have a refresh token or refresh endpoint that must be checked against server state, which is a session under another name. It is more moving parts for roughly the same behaviour Spring Session gives directly.
Does Redis become a single point of failure?
It becomes a dependency, so it needs replication and monitoring like any database. Many teams already run Redis for caching. A short Redis outage logs users out, which should be weighed against the risks of the JWT design.
When would you agree to the proposal?
If the team showed a real, measured problem the session store causes, and the application did not need instant logout or quick permission changes. That combination is rare for a server-rendered application with logged-in users.
7Conclusion
In this answer, we reviewed a proposal to replace server sessions with JWT cookies. The stateless benefit disappears once logout, revocation or permission changes are needed, the speed claim needs measurement, and the cookie still needs CSRF protection and must stay under about 4 KB. Spring Session with Redis already scales sessions across instances, so without a measured problem, keeping sessions is the better recommendation.
Open with
I would start by asking what measured problem this solves, because both claimed benefits are weaker than they sound. Stateless only holds until we need to end a session early.
Then, if they want more
With JWTs in a cookie, logging out just deletes the cookie in that browser; a copied token still works until it expires. Disabling a user or removing a role also does not take effect until the token is reissued.
To fix that we would need a deny list or a per-user version checked on every request, which is server state again.
On speed, a Redis session lookup is well under a millisecond, while the JWT version adds a signature check and a cookie of one or two kilobytes on every request, so I would want numbers before believing it is faster.
The cookie also still needs CSRF protection, since the browser sends it on cross-site requests like any cookie, and it has to stay under about four kilobytes. Meanwhile the scaling goal is already solved by Spring Session with Redis: sessions are shared, any instance serves any request, restarts lose nothing, and logout and sign-out-everywhere stay instant without code changes.
So my recommendation would be to keep sessions, move them to Spring Session if they are in memory, and only revisit JWTs if there is a measured problem or a real need to serve non-browser clients.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- RFC 7519, JSON Web Token
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A team proposes replacing server sessions with JWTs stored in cookies for a...": https://scrivio-interview-library.netlify.app/spring-boot/jwt/dce039691d/