Quick revision
The short answer
JWTs are the right choice for stateless verification between parties that share an issuer, such as APIs validating short-lived access tokens from one identity provider. They are a poor fit as browser user sessions, where revocation, permission changes and cookie size matter more than avoiding a lookup. Most incidents of the past decade came from misuse, such as missing audience checks, weak or shared keys, algorithm confusion and tokens in logs, so the board should standardise libraries and validation rules centrally and prefer opaque tokens or sessions where they are simpler.
What to remember
In this answer, we gave an architecture board a view of JWTs grounded in a decade of use. They are the right choice for short-lived access tokens verified locally by services sharing an issuer, and a poor one for browser sessions, long-lived credentials and large permission sets. Most incidents came from misuse, so the board should standardise libraries, algorithms and validation in a platform starter, and keep opaque tokens and sessions as simpler alternatives.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
JWTs are the right choice for stateless verification between parties that share an issuer, such as APIs validating short-lived access tokens from one identity provider. They are a poor fit as browser user sessions, where revocation, permission changes and cookie size matter more than avoiding a lookup. Most incidents of the past decade came from misuse, such as missing audience checks, weak or shared keys, algorithm confusion and tokens in logs, so the board should standardise libraries and validation rules centrally and prefer opaque tokens or sessions where they are simpler.
Why this question is asked
After a decade of JWTs being the default, an architecture board has enough history to judge them on evidence instead of fashion. Teams often reach for JWTs because they are familiar, not because the problem needs self-contained tokens, and many of the incidents in that time were not flaws in the format but in how it was used. Interviewers ask this at a senior level to see whether we can give guidance that is balanced and actionable: when to use JWTs, when not to, and how to stop the same mistakes recurring. In this answer, we will recap what a JWT actually offers, look at where it fits and where it does not, group the incident patterns, and set out what the board should standardise and which alternatives to keep on the table.
1What a JWT Actually Offers
A JWT is a signed set of claims that anyone with the issuer's public key can verify without calling the issuer. That one property is the reason to use it: verification is local, cheap and works even when the issuer is far away or briefly unavailable. The price is that the token cannot easily be changed or revoked once issued; it is valid until its expiry, and its contents are only as fresh as the moment it was signed.
So the board's guidance can be summarised as a question for each use: do we need verification without a lookup, and can we live with the token being unchangeable for its lifetime? If both answers are yes, a JWT fits.
2Where JWTs Fit Well
The best fit is access tokens between services that share an issuer. An identity provider issues a token valid for 5 to 15 minutes, and dozens of APIs verify it locally with cached keys. The short lifetime makes the revocation limitation acceptable, and the local check removes the identity provider from every request path. ID tokens in OpenID Connect, which tell a client who signed in, are another good fit, because they are read once at sign-in.
Signed, short-lived assertions between organisations also fit: a token that proves a request came from a partner, or a signed link that grants access to one file for five minutes. In each case the token is short-lived, its audience is specific, and nobody needs to revoke it mid-flight.
3Where They Fit Poorly
The weakest fit is the browser user session. Sessions need to end on logout, on password change and when an administrator disables an account; they need roles to change quickly; and they travel in cookies limited to about 4 KB and still need CSRF protection. A JWT session either ignores those needs or adds a deny list, which brings back the server state it was meant to remove. A server session, or a backend-for-frontend that keeps tokens on the server, is simpler and safer.
Long-lived tokens are another poor fit: API keys that are JWTs valid for a year, or refresh tokens issued as JWTs. Their value is that they can be revoked and checked, which an opaque token in a database does better. And large tokens carrying many claims, such as full permission lists, become slow to send and stale as soon as permissions change.
| Use case | JWT? | Better choice if not |
|---|---|---|
| Access tokens between services, one issuer | Yes, short-lived | - |
| OIDC ID token at sign-in | Yes | - |
| Short signed links and assertions | Yes, with narrow audience | - |
| Browser user session | No | Server session or BFF |
| Long-lived API keys | No | Opaque key in a database |
| Refresh tokens | Usually no | Opaque, stored by the issuer |
| Tokens with large permission lists | No | Look up permissions at the service |
4What the Incidents Had in Common
Looking back, very few JWT incidents broke the cryptography. Most fall into a handful of misuse patterns. Verifiers trusted the alg header, which allowed unsigned tokens with alg none, or algorithm confusion, where an RSA public key was used as an HMAC secret to forge tokens. Services skipped the audience check, so a token for one service worked at another. Teams used weak shared HMAC secrets that could be guessed offline from a single token. Tokens were logged in full, copied from logs and reused. Access tokens lived for days, so a leak lasted days. And tokens were kept in browser storage that an XSS bug could read.
The lesson for the board is that these are configuration and handling mistakes, made independently by many teams. The format did not prevent them, but neither did it cause them. That points to standardisation as the fix rather than banning JWTs.
5Standardise Instead of Leaving It to Each Team
The board should make the safe configuration the only easy one. A platform library or starter, in Spring a security starter around the OAuth2 resource server and NimbusJwtDecoder, fixes the allowed algorithms to asymmetric ones such as RS256 or ES256, fetches keys from the issuer's JWKS with bounded caching, and always validates issuer, audience and expiry. It masks Authorization headers in logs. Only the identity provider signs user tokens, and lifetimes are set centrally.
Teams then configure one thing, their audience, and contract tests in the starter check that bad tokens are rejected. Exceptions are documented with owners. This is how the board turns lessons from incidents into something that holds across hundreds of services.
- Identity providerOnly signer; asymmetric keys; JWKS with kid; lifetimes
- Platform security starterFixed algorithms, iss/aud/exp validation, log masking
- Service configurationOwn audience and scopes only
- Contract tests and scansReject bad tokens; find services off the starter
4 layers, from the top down. Step through them one at a time.
6Keep the Simpler Alternatives on the Table
Finally, the board should say plainly that JWT is not the default for every token. Opaque tokens, random strings that the issuer looks up, are simpler when revocation matters more than avoiding a lookup, and token introspection lets services check them. Server sessions remain the right answer for browser applications. A good review question for any new design is: what would break if this token were opaque? If nothing, the opaque token is probably the safer choice.
7Follow-up questions
Are JWTs insecure?
No. Signed JWTs with fixed asymmetric algorithms and proper claim validation are a sound design for short-lived access tokens. The incidents came from how they were configured and handled, which is why the advice is to standardise, not to ban them.
Should we encrypt JWTs?
Only if the claims must stay confidential from the client or intermediaries, using JWE. Most access tokens should simply avoid carrying sensitive data. Encryption adds key management and makes debugging harder, so it should be a deliberate choice.
How do we move teams off JWT sessions they already have?
Prioritise by risk, offer the platform BFF or session pattern as the replacement, and migrate when the application is next changed significantly. Until then, make sure those JWT sessions are short-lived and validated by the standard library.
8Conclusion
In this answer, we gave an architecture board a view of JWTs grounded in a decade of use. They are the right choice for short-lived access tokens verified locally by services sharing an issuer, and a poor one for browser sessions, long-lived credentials and large permission sets. Most incidents came from misuse, so the board should standardise libraries, algorithms and validation in a platform starter, and keep opaque tokens and sessions as simpler alternatives.
Open with
I would tell the board that JWTs solve one problem very well: letting many services verify a token locally, without calling the issuer. So they are the right choice for short-lived access tokens issued by one identity provider and checked by our APIs, for OIDC ID tokens, and for short signed links or assertions with a narrow audience.
Then, if they want more
They are a poor choice where we need to change or revoke things, and that is mostly browser sessions. A session has to end on logout or password change, roles have to update quickly, cookies are limited to about four kilobytes and still need CSRF protection, so a JWT session either ignores those needs or rebuilds server state.
Server sessions or a backend-for-frontend are simpler there, and long-lived API keys and refresh tokens are better as opaque tokens. Looking at the incidents over the last ten years, very few broke the cryptography.
They were misuse: trusting the alg header, which allowed alg none or algorithm confusion, skipping audience checks, weak shared HMAC secrets, tokens in logs, day-long lifetimes and tokens in localStorage.
Those are configuration mistakes made separately by many teams, so my main recommendation is to standardise: one platform starter that fixes asymmetric algorithms, validates issuer, audience and expiry and masks tokens in logs, with only the identity provider signing. And I would ask every new design what would break if the token were opaque.
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 "JWTs became the default token format across your industry. Looking at incidents over the...": https://scrivio-interview-library.netlify.app/spring-boot/jwt/a37c0fa051/