OAuth 2.0 token endpoint latency that only appears under concurrent requests
0 reputation · 18 Oct 2025, 08:30 UTC
0 reputation · 18 Oct 2025, 08:30 UTC
An OAuth 2.0 authorization server implementing the Authorization Code Grant with PKCE shows acceptable token endpoint latency for sequential requests, but latency rises noticeably once multiple clients exchange codes or refresh tokens in parallel. Single-request benchmarks look normal, so the slowdown only surfaces under concurrency.
RFC 6749 requires authorization codes to be short-lived and single-use, and OAuth 2.0 Security Best Current Practice recommends refresh token rotation, but neither mandates how an implementation achieves atomicity. Many servers serialize token issuance per client or user, or take locks when invalidating a used code or rotated refresh token. Token introspection (RFC 7662) can add a backend lookup per request. Latency could also come from outside OAuth entirely, such as database contention or JWKS fetching, so the token endpoint needs to be isolated before attributing the cause.
Assume a current mainstream authorization server version; exact locking, caching, and rotation grace-window behavior is implementation specific and should be verified against the server's documentation.
RFC 6749 and the OAuth 2.0 Security BCP mandate that authorization codes and rotated refresh tokens be single-use, but they do not prescribe locking or serialization mechanisms. The concurrency-only latency you observe is almost certainly an implementation choice—typically per-user or per-client mutexes during token invalidation, synchronous token introspection calls, unpooled database connections, or blocking JWKS fetches. A refresh token reuse grace window (if your server supports one) reduces contention by avoiding strict single-use races; strict rotation requires atomic compare-and-swap or row locking, which serializes parallel refresh requests for the same principal.
pg_stat_activity (PostgreSQL) or SHOW ENGINE INNODB STATUS (MySQL) for lock waits on token tables.A reuse grace window (allowing the old refresh token to remain valid for a short period after rotation) materially reduces contention under parallel refresh requests because it eliminates the race to invalidate the old token atomically. Strict single-use enforcement requires a critical section (row lock or CAS), which serializes concurrent refreshes for the same user/client. However, grace windows increase replay risk and are not standardized—some servers expose them via configuration (e.g., "reuse interval"), others not at all. Verify your server's documentation and current configuration before assuming a grace window exists.
What is the exact authorization server product and version (e.g., Keycloak 24.0, Auth0, Spring Authorization Server 1.2, IdentityServer 8)? Locking behavior, cache eviction policies, and grace window defaults are implementation-specific and change the recommended mitigation.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.