Course contentsShow
← System Design
Lesson 948 of 1,91924. Authentication and Authorization at ScaleFree lesson

Token Revocation at Scale

Implementing immediate token invalidation across distributed services when sessions must be terminated.

Token Revocation at Scale

What you'll learn: How to immediately invalidate tokens across multiple distributed services when a session must be terminated for security or business reasons.

The Revocation Challenge

When you need to revoke a token—whether due to user logout, security breach, or role change—the stateless nature of tokens works against you. Unlike sessions stored in a database, JWTs are self-contained and verified independently by each service. If a token is valid for 1 hour, services will accept it for that full hour unless you actively tell them it's been revoked.

At scale, broadcasting "this token is now invalid" to hundreds of services processing thousands of requests per second becomes a coordination problem.

Core Implementation Patterns

Revocation Lists (Deny Lists): Maintain a shared, fast-lookup store (Redis, Memcached) containing revoked token IDs (the jti claim). Before accepting a token, services check: "Is this token's ID in the deny list?" This adds a network hop but enables immediate invalidation.

Short-Lived Tokens with Refresh: Issue access tokens with very short lifespans (5-15 minutes). Revoke the refresh token instead. The access token naturally expires soon, limiting exposure.

Event-Driven Revocation: Publish revocation events to a message bus (Kafka, RabbitMQ). Services subscribe and maintain local in-memory caches of revoked tokens, dramatically reducing lookup latency.

Hybrid Approach: Combine short TTLs with selective deny lists—only revoke explicitly when immediate termination is critical (security incidents), accepting brief validity windows for routine logouts.

The Tradeoff

Token revocation reintroduces state into your stateless architecture. The key is balancing security requirements (how fast must revocation take effect?) against operational complexity and latency overhead.

Key Takeaway: Token revocation at scale requires maintaining a distributed deny list or event stream that all services can query efficiently, trading some statelessness for security control when immediate invalidation is non-negotiable.