Skip to the page

Auth and security · Trade-off

JWT or server-side sessions?

The interviewer asks

For a new web app plus an Android app, would you use JWTs or server-side sessions for login? Why?

Then

Follow-ups the interviewer asks next

  1. Where does the browser keep the token, and what are the risks of each place?
  2. How do you log a user out with a JWT?
  3. How big does a JWT get, and does it matter?
  4. What changes for the Android app?
  5. What did your last project use, and would you change it?

The answer

What a strong answer covers

  • Sessions: a random id in an HttpOnly; Secure; SameSite cookie, state in Redis or the database. Easy to revoke and small, but needs a shared store. Cookies need CSRF protection (SameSite=Lax helps; CSRF tokens for risky actions).
  • JWT: signed claims that any service can verify without a lookup. Can't be revoked before expiry without extra state, so keep access tokens short (5–15 minutes) with refresh tokens. The payload is only base64url-encoded, not encrypted: no personal data in it.
  • Browser storage: localStorage is readable by any XSS; an HttpOnly cookie isn't, so many teams put even JWTs in cookies.
  • Mobile: tokens in Keystore-backed secure storage; refresh tokens bound to the device.
  • A sensible default for a first-party web plus app: server sessions, or short access tokens with rotating refresh tokens tracked on the server. Use a tested library or identity provider rather than hand-rolling.

The red pen

Common traps

Avoid:"JWT is more secure"; "logout is just deleting it on the client"; putting passwords, PAN or Aadhaar numbers in the payload.

Practise this out loud

Say your answer out loud to an AI interviewer that follows up, and get a score for it.

Practise by voice

Practise questions like this out loud

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview