Auth and security · Trade-off
JWT or server-side sessions?
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe 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
- Where does the browser keep the token, and what are the risks of each place?
- How do you log a user out with a JWT?
- How big does a JWT get, and does it matter?
- What changes for the Android app?
- 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; SameSitecookie, state in Redis or the database. Easy to revoke and small, but needs a shared store. Cookies need CSRF protection (SameSite=Laxhelps; 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:
localStorageis 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 voicePractise 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.