Quick revision
The short answer
I would use the phantom token pattern: clients hold opaque tokens, the API gateway introspects each one and forwards a short-lived JWT to internal services, which validate it locally and stay fast. The gateway caches introspection results for a short, agreed time, so the cache TTL becomes the maximum revocation delay, a policy number signed off by security, and the introspection endpoint is sized and made highly available because it is now on the critical path.
What to remember
In this answer, we designed immediate revocation without slowing every service. Clients hold opaque tokens, the gateway introspects them and forwards a short-lived JWT, and internal services keep validating locally. The gateway's introspection cache bounds provider load, and its TTL is the maximum revocation delay, agreed with security as policy. The introspection endpoint becomes critical, so it is sized, replicated, monitored and given a decided failure behaviour.
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.
I would use the phantom token pattern: clients hold opaque tokens, the API gateway introspects each one and forwards a short-lived JWT to internal services, which validate it locally and stay fast. The gateway caches introspection results for a short, agreed time, so the cache TTL becomes the maximum revocation delay, a policy number signed off by security, and the introspection endpoint is sized and made highly available because it is now on the critical path.
Why this question is asked
Security and service owners both have good reasons here. Security wants a stolen or revoked token to stop working now, not in 15 minutes. Service owners know that asking the identity provider on every internal call would add latency to every hop and turn the provider into a single point of failure. Interviewers ask this design question to see whether we can find a structure where both are mostly satisfied and the remaining trade-off is a clear number. In this answer, we will see why plain JWTs and plain introspection both fail one side, build the phantom token design, decide the cache time, and make the introspection endpoint robust.
1Why Neither Simple Option Works
With JWT access tokens everywhere, each service validates tokens locally, which is fast, but a revoked token keeps working until its exp. Even with 10-minute tokens, a leaked token gives an attacker 10 minutes, and security says that is too long.
With opaque tokens everywhere, each service introspects every token it receives. A request that crosses five services makes five calls to the provider, each adding perhaps 10 to 20 ms, and the provider's load grows with all internal traffic. If the provider is slow, everything is slow. That is the service owners' fear, and it is justified.
2The Phantom Token Design
The idea is to use each token type where it is strong. Outside, clients receive opaque tokens: they reveal nothing and can be revoked instantly. At the edge, the API gateway introspects the opaque token once per request. If it is active, the gateway obtains a JWT that carries the same claims, either returned by the provider's introspection response or minted by the gateway with its own key, and forwards that JWT to internal services. Internal services validate the JWT locally, exactly as they do today.
7 messages in order. Play them, or step through them one at a time.
Only the gateway talks to the provider; internal hops stay local and fast.
Notice how revocation works now. When security revokes a token, the next request through the gateway introspects it and gets active: false, so the request stops at the edge. The internal JWT lives for very little time, for example 60 seconds or just the request, and it never leaves our network, so it cannot be stolen from a browser or a mobile app.
3Choosing the Cache Time Together With Security
Introspecting every single request at the gateway would still put all external traffic on the provider. So the gateway caches results, keyed by a hash of the token, for a short time. If clients send 20,000 requests per second from 50,000 active tokens and we cache for 30 seconds, introspection traffic falls to about 50,000 calls every 30 seconds, roughly 1,700 per second, instead of 20,000.
The cost of that cache is that a revoked token can keep working for up to the cache time. This is the part to make explicit. We do not choose 30 seconds in a code review; we agree with security on a maximum revocation delay, write it down as policy, and set the TTL from it. If security says 10 seconds, we size the provider for that load. For the highest-risk events, such as an account takeover, the provider can also notify the gateway to evict cached entries for that user, so the common case is cheap and the urgent case is immediate.
| Gateway cache TTL | Introspection calls per second | Worst revocation delay |
|---|---|---|
| none | about 20,000 | immediate |
| 10 seconds | about 5,000 | 10 seconds |
| 30 seconds | about 1,700 | 30 seconds |
| 120 seconds | about 420 | 2 minutes |
4Making Introspection a Critical Service
In this design the introspection endpoint is on the path of every external request, so it must be treated like the gateway itself. We run several instances across zones, load test it at peak traffic with the chosen TTL, and watch its latency and error rate as service-level indicators. The gateway calls it with tight timeouts and a circuit breaker.
We also decide what happens when it fails. Failing closed, rejecting requests, is the secure default. Some teams allow cached results to be served a little past their TTL during an outage, which keeps the platform up at the cost of a longer revocation delay for those minutes. That is again a policy decision for security, made in advance rather than during an incident.
5What Internal Services Change
Very little, which is the point. They validate a JWT with the gateway's or provider's public key, check the issuer and audience, and keep their @PreAuthorize rules. They should reject tokens that did not come through the gateway, for example by trusting only the internal issuer and audience, so nobody bypasses the edge with an old external token.
6Follow-up questions
Why not just shorten JWT lifetimes to one minute?
It narrows the window, but clients must then refresh every minute, which multiplies load on the token endpoint and still leaves a minute of exposure. The phantom design gives near-immediate revocation without changing clients at all.
Does the gateway become a security risk itself?
It holds the power to mint or forward internal tokens, so it must be hardened, its signing key kept in a key store, and internal services must trust only its issuer. But it already sees every request, so concentrating this responsibility there adds less risk than spreading introspection across all services.
What about service-to-service calls that do not pass the gateway?
Those use their own client credentials tokens, usually JWTs with short lifetimes, because revoking a service's access is rare and can be done by rotating its credentials. The immediate-revocation requirement mainly concerns user tokens held by clients outside our network.
7Conclusion
In this answer, we designed immediate revocation without slowing every service. Clients hold opaque tokens, the gateway introspects them and forwards a short-lived JWT, and internal services keep validating locally. The gateway's introspection cache bounds provider load, and its TTL is the maximum revocation delay, agreed with security as policy. The introspection endpoint becomes critical, so it is sized, replicated, monitored and given a decided failure behaviour.
Open with
I would use the phantom token pattern. Clients get opaque tokens, which can be revoked instantly and reveal nothing if they leak. The API gateway introspects each token at the edge and, if it is active, forwards a short-lived JWT with the same claims to internal services.
Then, if they want more
Internal services keep validating JWTs locally, so there is no extra network call on internal hops and service owners see no latency change. To keep load on the identity provider reasonable, the gateway caches introspection results by token hash for a short time.
That TTL is the maximum revocation delay, so I would not pick it myself: I would agree it with security as a written policy, say 30 seconds, and size the provider for it. For urgent cases like account takeover, the provider can push an eviction to the gateway.
Because introspection is now on the path of every external request, I would run that endpoint highly available across zones, load test it at peak, monitor it as a key service, and agree in advance whether the gateway fails closed or serves slightly stale results during an outage.
Internal services should trust only the internal issuer, so nobody can bypass the gateway with an external token.
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 6749, The OAuth 2.0 Authorization Framework, Spring Security reference, OAuth2
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 "Your security team wants immediate token revocation for all APIs, but service owners...": https://scrivio-interview-library.netlify.app/spring-boot/oauth2-and-oidc/26718deef3/