Scrivio Interview library
DesignAdvanced7 min read · updated 12 November 2026

Your company runs 60 web applications, some on server sessions with Spring Session and Redis, some on JWTs stored in browser storage, some on sticky sessions. Define the session standard for web and mobile clients.

The standard separates clients: browser applications use server-side sessions carried in HttpOnly, Secure, SameSite cookies, with a backend-for-frontend for single-page apps, while mobile apps and services use OAuth 2 tokens. Server sessions are stored in one supported way, Spring Session on a managed Redis or JDBC store, with agreed idle and absolute timeouts, fixation protection and logout-everywhere through an indexed repository. The session store is treated as a tier-1 dependency, and sticky-session applications migrate first because they block autoscaling and zero-downtime deploys.

Background to this question

When 60 applications each solved sessions their own way, the company gets 60 different security postures, 60 sets of bugs and no way to answer a simple question like how to log a user out everywhere. A staff-level engineer is asked to define the standard because it mixes security, operations and migration planning. In this answer, we will recap the three models in use, compare their real costs, define the standard for each client type, specify the shared session platform, plan for the store being down, and order the migration.

1A Quick Recap of the Three Models

A server-side session keeps the user's state on the server, in memory or in a store, and gives the browser only a random id in a cookie. A JWT, a JSON Web Token, puts the user's claims into a signed token that the client presents on each request, so the server can check it without a lookup. Sticky sessions keep server state in the memory of one instance and ask the load balancer to always send the same user there.

The three are not just storage choices. They decide where a stolen credential can be used, how fast we can revoke access, and whether we can restart an instance without logging people out.

2Comparing the Costs Honestly

Server sessions give immediate revocation: delete the session and the next request is anonymous. The cookie is small, around 40 bytes, and if it is HttpOnly, JavaScript cannot read it, so a cross-site scripting bug cannot steal it directly. The price is a lookup on every request and a store that must be available.

JWTs avoid the lookup, which is valuable between services. But a JWT stays valid until it expires, so revoking one needs a deny list, which brings the lookup back. JWTs also tend to grow, often to 1 to 2 KB with roles and claims, and they carry data such as emails and roles that anyone holding the token can decode. Stored in localStorage, they are readable by any script on the page, which turns one XSS bug into stolen sessions.

Sticky sessions cost nothing at first, but they lose every user on an instance whenever it restarts, they make load uneven and they make autoscaling and zero-downtime deploys painful.

The standard per client type
ClientMechanismWhere the credential lives
Server-rendered web appSpring Session server sessionHttpOnly, Secure, SameSite=Lax cookie
Single-page appBackend-for-frontend holds OAuth tokensSession cookie to the BFF; tokens stay server-side
Mobile appOAuth 2 authorization code with PKCEShort access token, rotated refresh token in secure storage
Service to serviceOAuth 2 client credentials or mTLSShort-lived token, never a user session
JWTs in browser storage and sticky sessions are not allowed for new applications.

3Browsers: Cookies and a Backend-for-Frontend

For browser applications the standard is a server session in a cookie marked HttpOnly (no script access), Secure (HTTPS only) and SameSite=Lax (not sent on most cross-site requests, which blocks most CSRF). Single-page apps that today keep a JWT in localStorage move to a backend-for-frontend: a small server, often Spring Cloud Gateway or a Spring Boot app, that performs the OAuth login, keeps the tokens on the server side, and gives the browser only a session cookie. The SPA calls its BFF, and the BFF adds the access token when it calls the APIs.

Mobile apps cannot use cookies well and run outside our domain, so they use OAuth 2 with authorization code and PKCE, short access tokens of 5 to 15 minutes, and refresh tokens that rotate on every use, so a stolen refresh token is detected the next time either copy is used.

4The Shared Session Platform

Standardizing the client side only works if the server side is also one thing. We offer Spring Session on a managed Redis as the default, and the JDBC store for small applications that already depend on a database. A shared starter library sets the defaults so that teams do not copy configuration.

Properties
# defaults set by the company's session starter
spring.session.redis.repository-type=indexed # enables find-by-principal for logout everywhere
spring.session.redis.namespace=spring:session:${spring.application.name}
spring.session.timeout=30m # idle timeout
server.servlet.session.cookie.http-only=true
server.servlet.session.cookie.secure=true
server.servlet.session.cookie.same-site=lax
company.session.absolute-timeout=12h # enforced by a small filter in the starter

Notice the last line. Spring Session gives us an idle timeout, but an absolute limit, after which the user must log in again however active they are, is not built in. The starter adds a filter that compares the session's creation time with the limit and invalidates older sessions. Session fixation protection comes from Spring Security, which changes the session id on login by default; the standard simply forbids turning it off.

Logout everywhere relies on the indexed repository, which keeps an index from the principal name to its session ids, so we can find and delete all sessions of one user.

5Planning for the Store Being Down

Once 60 applications depend on it, the session store is a tier-1 dependency and must be planned like one. We size it from real numbers: for example 2 million active sessions of about 2 KB each is 4 GB of data, plus index keys and headroom, on a replicated cluster with automatic failover across zones. Each application should have a separate namespace, and the largest ones can get their own cluster so that one noisy application cannot hurt the rest.

We also define behaviour when the store is unreachable. The standard says applications fail closed for anything that needs a login, returning a clear 503 page rather than treating users as anonymous or crashing with a 500, and public pages keep working because they do not touch the session. We test this regularly by failing over the store in a staging environment.

6Ordering the Migration

Sticky-session applications go first, because they are the ones blocking autoscaling and zero-downtime deployments, and the change is small: add the starter and make session attributes serializable. Next come SPAs with JWTs in browser storage, since they carry the largest security risk, moving to the BFF pattern. Applications already on Spring Session only need to adopt the starter's defaults. We track progress on a simple dashboard per application and set a date after which a non-compliant application needs an exception approved by security.

Step throughMigration order
  1. Sticky-session appsmove to Spring Session; unblocks autoscaling
  2. JWT-in-browser SPAsmove tokens behind a BFF; biggest security gain
  3. Existing Spring Session appsadopt starter defaults and indexed repository
  4. Exceptionsreviewed by security with an end date

4 steps in order. Play them, or step through them one at a time.

7Follow-up questions

How would you implement 'log out from all devices'?

For browser sessions, the indexed repository lets us call findByPrincipalName with the user's name, which returns all their sessions, and then delete each one by id; on the next request each device is anonymous. For mobile and BFF clients, we also revoke the user's refresh tokens at the authorization server, so no new access tokens can be issued, and the short lifetime of access tokens limits the remaining window to a few minutes. The button in the UI calls one endpoint that does both and records an audit event.

Why not let every app use JWTs to avoid the store entirely?

Because we would trade a store we can operate for revocation problems we cannot solve without a store. A deny list for revoked tokens is itself a lookup on every request, and browser-stored tokens remain exposed to XSS. Tokens are the right tool between services and for mobile, not as the browser session.

How do you keep 60 teams on the standard?

We make the compliant path the easiest: a starter with the defaults, a template project, and automated checks in CI that flag sticky-session settings or tokens written to localStorage.

8Conclusion

In this answer, we defined a session standard by client type: server sessions in HttpOnly, Secure, SameSite cookies for browsers, a backend-for-frontend for single-page apps, and OAuth 2 tokens for mobile and services. We compared the real costs of sessions, JWTs and sticky sessions, standardized Spring Session on managed Redis or JDBC through a starter with idle and absolute timeouts, fixation protection and an indexed repository for logout everywhere, treated the store as tier-1 with defined behaviour when it is down, and migrated sticky-session applications first.

What to say in the interviewAbout 90 seconds aloud

Open with

I would start by separating clients rather than picking one mechanism for everything. Browser applications use server-side sessions in cookies that are HttpOnly, Secure and SameSite, and single-page apps use a backend-for-frontend so tokens never sit in browser storage.

Then, if they want more

Mobile apps use OAuth 2 with PKCE, short access tokens and rotating refresh tokens, and services use client credentials. The reason is revocation and exposure: a server session can be killed instantly and the cookie carries nothing but an id, while a JWT stays valid until it expires and, in localStorage, is readable by any script after an XSS bug.

For server sessions there is one supported platform: Spring Session on a managed Redis, or JDBC for small apps, delivered as a company starter that sets a per-app namespace, a 30-minute idle timeout, a 12-hour absolute limit, keeps Spring Security's fixation protection, and uses the indexed repository so we can find all sessions of a user for logout everywhere.

The store becomes a tier-1 dependency: sized from real session counts, replicated across zones, and with a defined failure mode where logged-in features return a clear 503 instead of random errors. For migration I would take the sticky-session apps first, because they block autoscaling and zero-downtime deploys, then the SPAs with tokens in browser storage, and track compliance per application.

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
Spring Boot reference
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 "Your company runs 60 web applications, some on server sessions with Spring Session and...": https://scrivio-interview-library.netlify.app/spring-boot/spring-projects/b2d3319086/