Skip to content

Sessions vs JWT

Opaque server-side sessions or self-contained signed tokens: what each costs in lookups, revocation and size, how to validate a JWT safely, and where to keep it.

25 min6 steps

By the end you can
  • Compare server-side sessions with self-contained tokens on revocation, lookup cost and size
  • List the checks a server must make before trusting a JWT
  • Size a denylist for revoking self-contained tokens before they expire
  • Choose access and refresh token lifetimes by trading revocation delay against refresh load
  • Choose where a browser keeps a credential, and which cookie attributes protect it

A pointer or a passport

A JWT is signed, not encrypted: never put secrets in it.

Server-side session

  • Opaque random ID (64+ bits)
  • Store lookup per request
  • Revoke instantly: delete row

JWT (RFC 7519)

  • Signed claims: sub, exp, aud
  • No lookup, any service verifies
  • Valid until exp; bigger per request

A banking web app must end every session within seconds when a user clicks 'sign out everywhere' or support suspects fraud. Traffic is moderate and served from one region. Which design fits best?

Answer this step to continue.