Q16: How can you revoke stateless JWT access tokens before their natural expiration?

Difficulty:MediumTopic:Architecture Patterns

Because JWTs are stateless, instant token revocation requires adding specific tracking mechanisms:

  1. Short Lifespans + Refresh Tokens: Keep access token lifespans extremely short (e.g., 5 minutes); revoke access by invalidating the refresh token on the Auth Server.
  2. Token Denylist / Blacklist in Redis: Store revoked JWT jti (JWT ID) claims in an in-memory Redis cache with TTL equal to the remaining expiration time. APIs check Redis during request processing.
  3. User Token Versioning: Store an integer token_version on the User database record and inside the JWT payload. Incrementing the database token_version immediately invalidates all active tokens for that user.
Key Takeaways
  • Keep JWT lifespans short to minimize the window of compromise.

  • Use Redis jti blacklists or token_version counters for instant multi-device logout enforcement.