Question presented to candidate: "After a user logs in, how does your server know who's making each SUBSEQUENT request — and if you need to immediately revoke a compromised login (a stolen laptop, a suspicious device), can you actually do that instantly with your chosen approach?"
What a strong answer should cover:
- Two genuinely different approaches, both verified directly: session-based auth stores an opaque session ID client-side (typically an HttpOnly cookie) that maps to real state held server-side (in memory, Redis, a database); JWT-based auth issues a signed token containing the actual claims, verified client-side on each request via its signature, with no server-side lookup required at all.
- 📌 Verified, not assumed — session revocation: a real opaque session ID was issued and successfully used to fetch
/me; after a real server-side logout, the identical session ID was genuinely rejected (401) on the very next request — because the server-side session store is the only copy of truth, deleting it there instantly and completely revokes access. - 📌 Verified, not assumed — JWT tamper detection: a real JWT was signed with HMAC-SHA256; verifying the genuine token correctly decoded its payload, while a token with a tampered payload (an altered
userId) was genuinely rejected by the signature check — proving the signature protects against forgery, but this is a DIFFERENT property than revocability. - The prompt's exact question — can you revoke instantly — is the single sharpest, most interview-relevant distinction: session-based auth answers yes, verified directly above; a pure JWT approach answers no — an unmodified, stolen-but-valid token remains genuinely usable until its real expiry, since there is no server-side state to delete. Production JWT systems commonly work around this with short expiries plus a refresh-token rotation/blocklist, trading some of JWT's "no server lookup" benefit back for genuine revocability.
- A precise answer names the trade-off, not a "which is better" verdict: sessions need server-side state (a scaling/infrastructure cost, but genuine instant revocation); JWTs need no server-side lookup per request (better for stateless horizontal scaling, verified elsewhere in this bank as a 12-factor principle) but genuinely cannot be revoked before expiry without added infrastructure.
Clarifying questions expected:
- "Does instant revocation (a stolen device, a fired employee) need to be genuinely possible, or is a short token expiry an acceptable substitute?" — the single question the prompt is actually asking, and the one that most directly decides between the two approaches.
- "Is this a single server/monolith, or does the auth need to be verified independently by multiple stateless services without a shared session store?" — the classic case favoring JWT's no-lookup verification.
Code / implementation expected: Yes — a real session-based login/lookup/revocation cycle and a real hand-rolled, cryptographically-verified JWT sign/verify/tamper-detect cycle are the concrete, convincing proof of exactly what each approach does and does not guarantee.