← Lessons

quiz vs the machine

Platinum1720

System Design

Session and Token Revocation

Invalidating credentials before they expire when a user logs out or is compromised.

6 min read · advanced · beat Platinum to climb

The stateless dilemma

Self contained tokens are fast because no lookup is needed, but that means a leaked token stays valid until it expires. When a user logs out or an account is compromised, you need to revoke access immediately, which fights against statelessness.

Strategies

  • Short lived access tokens with a refresh token limit exposure; revoke by refusing to issue new access tokens at refresh.
  • A revocation list tracks revoked token identifiers, checked on each request for instant effect at the cost of a lookup.
  • Token versioning stores a counter per user; bumping it invalidates all of that user existing tokens at once.

Picking a balance

Pure statelessness gives speed but slow revocation. Adding a small denylist or version check restores fast revocation while keeping most validation local. The right point depends on how fast you must cut off a compromised session.

Key idea

Revocation trades statelessness for speed of cutoff, using short lifetimes plus a denylist or version counter to invalidate tokens before they expire.

Check yourself

Answer to earn rating on the learn ladder.

1. Why is immediate revocation hard with self contained tokens?

2. How does token versioning revoke access?

3. What is the cost of checking a revocation list on each request?