skip to content

Compare opaque introspected tokens with self-contained JWTs for a resource server. What are the trade-offs, and when would you pick each?

level: seniorimportance: must knowfreq 58%

answer

  1. Local verify vs network introspection
  2. JWT: fast, no revocation, readable claims
  3. Opaque: instant revoke, private, per-request round-trip
  4. AS-down: JWT survives, opaque fails
  5. Cache introspection = the middle ground

basics

~20 s

JWTs are validated locally (fast, no network) but can't be revoked until they expire and expose claims to anyone. Opaque tokens require a network introspection call per request (slower, central dependency) but give instant revocation and keep claims private. Choose opaque when revocation matters, JWT for scale/latency.

solid answer

~50 s

The core trade-off is local validation versus a network lookup. A JWT is self-contained and signature-verified locally, so validation is fast, needs no round-trip, and lets the resource server keep working even if the authorization server is down — but the token stays valid until exp, so revocation is hard (you need denylists or short lifetimes), its claims are readable by anyone who holds it, and rotating signing keys / claims across services is a coordination cost. An opaque token carries no data; every request calls the RFC 7662 introspection endpoint, giving instant revocation, a single source of truth, no leaked claims, and freedom to change token internals server-side — at the cost of per-request latency, load and a hard runtime dependency on the authorization server. Pick JWT for high-throughput, latency-sensitive, loosely-coupled systems; pick opaque when immediate revocation, confidentiality, and central control outweigh the round-trip. Caching introspection responses is the usual middle ground.

go deeper

for a junior

Know the one-liner: JWT = fast/local but hard to revoke; opaque = network check but revocable.

for a middle

Should articulate 3-4 concrete trade-offs (latency, revocation, confidentiality, AS coupling).

for a senior

Should give a decision guide and mention caching as the middle ground plus AS-availability implications.

for a principal

Reasons about hybrid topologies (short-lived JWT + refresh, edge-JWT/introspect-for-sensitive-ops), cache TTL as a revocation-latency knob, and org-wide operational cost.

## Two validation models | Concern | Self-contained **JWT** (`.jwt()`) | **Opaque** token (`.opaqueToken()`) | |---|---|---| | Validation | **Local**: verify signature with the AS's public key (fetched once from JWK Set), check `exp`/`iss`/`aud` | **Remote**: `POST` to RFC 7662 introspection endpoint every request | | Network per request | **None** (JWKs cached) | **One round-trip** unless cached | | AS availability coupling | Loose — works if AS is down (keys cached) | Tight — AS down ⇒ can't validate ⇒ 401/503 | | Revocation | **Hard** — valid until `exp`; need denylist or very short TTL | **Instant** — AS reports `active:false` immediately | | Confidentiality of claims | Payload is base64 (not encrypted) — **readable by anyone** | Token is opaque — **claims never leave the AS** | | Token size on the wire | Larger (carries all claims) | Small (a random handle) | | Changing claims/authorities | Requires re-issue + cross-service coordination | Change centrally; introspection reflects it next call | | Scaling | Excellent — pure CPU, horizontal | Bounded by introspection endpoint throughput | ## Why JWTs can't be easily revoked A JWT is a bearer credential that is trusted purely because its signature verifies and it hasn't expired. Once issued, the resource server never consults the AS, so a logout / compromised-token event can't be honored until `exp`. Mitigations — short lifetimes plus refresh tokens, or a shared revocation/denylist — reintroduce state and, in the denylist case, a per-request lookup that erases much of the JWT latency advantage. ## Why opaque tokens cost latency Every protected request triggers `introspect(token)` → HTTP call → JSON parse. Under load this makes the introspection endpoint a **bottleneck and a single point of failure**. Standard mitigation: **cache introspection results** keyed by the token, bounded by the token's `exp`. Caching trades a little revocation immediacy (up to the cache TTL) for large latency/throughput gains — a tunable knob between the two models. ## Confidentiality & PII Because a JWT's payload is only base64url-encoded, any party (including the browser or a proxy) can read `sub`, roles, email, etc. If tokens must not leak claims, opaque tokens keep everything server-side. ## Decision guide - **Prefer JWT** when: high request volume, latency-sensitive APIs, many independently-deployed resource servers, tolerance for token lifetime as the revocation window, and no sensitive claims in the payload. - **Prefer opaque** when: you need **immediate revocation** (banking, admin sessions), tokens carry confidential data, or you want the AS to remain the single authority on every call — and the introspection latency/coupling is acceptable (often softened by caching). - **Hybrid patterns**: short-lived JWTs + refresh (approximate revocation), or JWT at the edge with introspection only for high-value operations. ## Spring specifics The two are configured on different builder paths — `oauth2ResourceServer().jwt()` vs `.opaqueToken()`. They are not interchangeable at runtime for the same request unless you wire an `AuthenticationManagerResolver` to pick per token. Both ultimately populate an `Authentication` in the `SecurityContext` (`JwtAuthenticationToken` vs `BearerTokenAuthentication`).

  • How can you get near-immediate revocation while still using JWTs?
    Use short-lived access tokens (seconds-to-minutes) paired with refresh tokens, or maintain a shared revocation denylist the resource server checks. Both add state/lookups, partly eroding the JWT no-network advantage.
  • How do you keep opaque tokens performant at scale without losing all revocation benefit?
    Cache introspection responses keyed by the token, bounded by exp and a short TTL. Revocation is then honored within the TTL window — a tunable trade of immediacy for latency/throughput.
  • If the authorization server goes down, what happens under each model?
    JWT resource servers keep validating using cached JWKs (loose coupling). Opaque-token resource servers can't introspect and fail requests (tight coupling), unless a cache still holds valid results.

saying these in an interview costs you the question

  • Claiming JWTs can be revoked as easily as opaque tokens without extra machinery
  • Saying JWT payloads are encrypted/secret (they are only base64url-encoded)
  • Ignoring the authorization-server availability coupling of introspection
  • Asserting opaque tokens are always more secure (it depends on requirements; they trade latency/coupling)

context