Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

Set the token lifetime policy for web sessions, mobile apps and service-to-service tokens in your company. What lifetimes and rules would you choose, and how would you justify them?

Access tokens should be short everywhere, in the range of minutes, with the exact values agreed with security based on how quickly a revocation must take effect. Refresh tokens get rotation and reuse detection for public clients and idle plus absolute limits per client type, service-to-service tokens are short-lived and fetched automatically so no static long-lived tokens exist, and sensitive actions require recent re-authentication regardless of token age. The policy is reviewed against incident and user-experience data rather than set once.

Why this question is asked

Token lifetimes look like small configuration values, but together they decide how long a stolen token is useful, how often customers are asked to sign in, and how much load the identity provider carries. When every team picks its own values, we end up with a 24-hour access token in one service and a 5-minute session in another, and nobody can explain either. Interviewers ask this at a senior level because they want to hear a reasoned policy, not a list of numbers. In this answer, we will set the principles, choose lifetimes for web sessions, mobile apps and service tokens, add re-authentication for sensitive actions, and decide how the policy is justified and kept current.

1The Principles Behind the Numbers

Three facts drive the policy. First, a JWT access token is validated locally by each API and usually cannot be revoked, so its lifetime is the worst-case delay before a revocation takes effect. Second, a refresh token is checked by the authorization server on each use, so it can be revoked, and its lifetime mostly decides how often a user must sign in. Third, sessions differ by risk and by device: a shared office browser, a personal phone and a backend service have very different threats.

So the policy treats the access token lifetime as a security parameter and the refresh token limits as a user-experience parameter with security guard rails. That separation is what lets us justify each number to the right people.

2Access Tokens: Minutes Everywhere

The rule is short access tokens for every client type, typically 5 to 15 minutes. The exact value comes from a conversation with security: if the requirement is that a disabled user or a stolen token must stop working within 15 minutes, then 15 minutes is the upper bound and 10 gives some margin. Going much shorter, like one minute, multiplies refresh traffic for little gain; a million active users with 10-minute tokens already means about 1,700 refreshes a second at peak.

Keeping one value for all clients also keeps reasoning simple. When someone asks how long a revoked user can still act, the answer is the same for every channel.

3Refresh Tokens and Sessions per Client Type

Refresh tokens are where the client types differ. Each gets an idle limit (the session ends if not used for that long) and an absolute limit (the session ends after that long no matter what). Public clients, meaning mobile apps and browser apps that cannot keep a secret, always use rotation with reuse detection, so a stolen refresh token is caught on its second use.

For browser applications, we prefer a backend-for-frontend, a small server that holds the tokens and gives the browser only an HttpOnly session cookie. Then the browser never holds a refresh token at all, and the session limits apply to the server-side session.

Example lifetime policy
Client typeAccess tokenRefresh / sessionExtra rules
Web (BFF, cookie session)10 minIdle 30 min, absolute 12 hShorter on shared devices
Mobile app10 minIdle 30 days, absolute 90 daysRotation, reuse detection, device-bound if possible
Admin consoles5 minIdle 15 min, absolute 8 hMFA at sign-in
Service to service5 to 15 minNone (client credentials)Fetched and cached automatically
Sensitive actionsAnyAnyRe-authenticate if sign-in older than 5 to 15 min
Illustrative values; the real numbers are agreed with security and product.

4Service-to-Service Tokens

Backend services get tokens through the client credentials grant: the service authenticates to the authorization server with its own credentials (ideally a private key or workload identity rather than a shared secret) and receives a short-lived access token. A library, such as Spring Security's OAuth2 client with its authorized client manager, fetches and caches the token and gets a new one before it expires, so no human ever handles it.

The rule this enables is that no long-lived static tokens exist. A token pasted into a configuration file a year ago is the kind of credential that leaks through a repository or a log and works for months. If a service cannot obtain tokens automatically, that is a gap to fix, not an exception to grant.

5Re-Authentication for Sensitive Actions

Some actions should not depend on how long a session has been alive: changing the password or email address, adding a payee, viewing full card details, or exporting data. For those, the policy requires recent strong authentication, for example a sign-in or multi-factor check within the last 5 to 15 minutes. In OpenID Connect this is visible through the auth_time claim and can be requested with max_age or a step-up prompt.

This decouples convenience from risk. A mobile user can stay signed in for weeks to browse their account, and still be asked for a fingerprint or code before moving money. That is what lets us keep long sessions where the product needs them without accepting their risk everywhere.

6Justifying and Reviewing the Policy

Each number in the policy should have a written reason: the access token lifetime is the agreed revocation delay, the mobile absolute limit balances sign-in friction against device loss, the admin limits reflect higher privilege. The policy is delivered through the identity provider's client settings and the platform security starter, so teams do not set lifetimes individually.

Then we measure. Security brings incident data, such as stolen-token cases and how long they were usable. Product brings data on forced sign-ins, drop-off at sign-in and support tickets. Operations brings refresh traffic and identity provider load. A review every six to twelve months, or after a significant incident, adjusts the numbers with evidence instead of opinion.

Step throughHow a lifetime decision is made
  1. State the riskRevocation delay, device loss, privilege
  2. Propose valuesPer client type
  3. Check user impactSign-in frequency, drop-off
  4. Agree with security and productWritten reason per number
  5. Deliver centrallyIdentity provider and starter
  6. Review with dataIncidents, support, load

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

7Follow-up questions

Why not make mobile access tokens longer, since phones are personal?

Because the access token lifetime is about revocation, not about the device. A stolen access token from a phone works just as well on an attacker's laptop. We give mobile users convenience through a long, rotated refresh token instead, which the server can still revoke.

What about long-running batch jobs that run for hours?

They refresh their service token automatically like any other service, rather than getting a token that outlives the job. The client library handles renewal, so the job never needs a multi-hour token.

How do you stop teams from ignoring the policy?

By delivering it centrally. Lifetimes live in the identity provider's client configuration, which the platform team owns, and the starter sets validation defaults. A periodic report of client settings shows any drift.

8Conclusion

In this answer, we built a token lifetime policy from a few principles. Access tokens are minutes long everywhere because their lifetime is the revocation delay, with the value agreed with security. Refresh tokens and sessions vary by client type, with rotation and reuse detection for public clients and idle and absolute limits for all. Service tokens are short and automatic, sensitive actions require recent authentication, and the policy is reviewed against incident and user data.

What to say in the interviewAbout 90 seconds aloud

Open with

I would build the policy on one distinction. Access tokens are validated locally and usually cannot be revoked, so their lifetime is how long a revoked user or stolen token can still work.

Then, if they want more

That is a security decision, so I would keep access tokens short everywhere, around ten minutes, with the exact value agreed with security based on how fast revocation must take effect. Refresh tokens are checked by the authorization server each time, so their limits are more about how often users sign in.

For web I would use a backend-for-frontend with a cookie session, an idle limit of about thirty minutes and an absolute limit of about twelve hours. For mobile, longer refresh tokens, maybe thirty days idle and ninety days absolute, but always with rotation and reuse detection, and bound to the device where possible. Admin tools get tighter limits and MFA.

Service-to-service calls use client credentials with short tokens that the library fetches and renews automatically, so we never have long-lived static tokens in configuration. Independently of token age, sensitive actions like changing the email or adding a payee require recent strong authentication.

I would justify each number in writing, deliver the values centrally through the identity provider and the platform starter, and review the policy every six to twelve months with incident data, sign-in drop-off and support tickets.

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 "Set the token lifetime policy for web sessions, mobile apps and service-to-service...": https://scrivio-interview-library.netlify.app/spring-boot/jwt/f783adb1a6/