Introspection endpoint per request versus short-lived JWT with cached revocation: selecting cache TTL for latency-sensitive APIs
0 reputation · 18 Dec 2021, 18:19 UTC
0 reputation · 18 Dec 2021, 18:19 UTC
Determine an appropriate cache lifetime for OAuth introspection responses that satisfies low-latency validation while providing acceptable revocation guarantees for latency-sensitive APIs.
What maximum acceptable staleness for revocation can be tolerated given the API’s latency budget? How should the cache TTL be tuned relative to observed token revocation frequency and issuance patterns? Should the resource server treat a cached introspection response as stale after a fixed period and fall back to a fresh introspection call?
35275 reputation · 19 Dec 2021, 06:01 UTC
For a latency‑sensitive API the cache TTL for introspection responses should be set to the largest value that keeps the post‑revocation exposure window within the tolerance you have agreed for your application. In other words, the staleness introduced by caching must not allow a revoked token to be accepted for longer than the time you are willing to tolerate that risk.
The practical choice of TTL is driven by three measurable inputs:
A common heuristic is to cache for a fraction of the token lifetime (e.g., 30–50%) but not to exceed the exposure window. For example, with a 10‑minute token and a 60‑second exposure tolerance, a TTL of 60 seconds is acceptable; a TTL of 5 minutes would expose the system to a revocation window that exceeds the tolerance.
If revocations are frequent or the exposure window must be very short, you can keep the TTL very low (e.g., 10–30 seconds) or fall back to per‑request introspection for tokens that appear revoked in a fast revocation store (Redis set, Bloom filter, etc.). Conversely, if revocations are rare and latency is critical, a longer TTL may be acceptable.
Treat a cached entry as stale when its age exceeds the chosen TTL. On a cache miss or when a fast revocation check indicates the token may have been revoked, trigger a fresh introspection call. This keeps the hot path local for the common case while ensuring that revocation is enforced promptly when needed.
To set a safe TTL you need to know the maximum post‑revocation exposure window you can tolerate (in seconds). Without that figure the TTL cannot be bounded safely.
Because these factors vary by deployment, the TTL recommendation should be validated against real traffic and latency measurements before being committed to production.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.