Auth and identity · Comparison

Sessions vs JWT

Both keep a person signed in after they log in. A session keeps the facts on the server and gives the browser a random key; a JWT packs the facts into a signed token that the client carries around.

2 options · 8 questions side by side · updated

CompareSessionsJWT
What the client holdsA random session ID in a cookieA signed token with the user's details
Where the truth livesA server-side store (database or Redis)Inside the token itself
Checking a requestLook the ID up in the storeVerify the signature; no lookup needed
Signing someone outDelete the record; works at onceHard before expiry; needs short lifetimes or a deny list
Many serversAll must reach the same storeAny server with the key can verify
Size on each requestA short IDHundreds of bytes or more, growing with claims
Mobile apps and APIsPossible, but cookies are awkwardA natural fit, sent as a bearer token
Watch out forCSRF: use SameSite cookies and CSRF tokensTheft through XSS if kept in localStorage

How to choose between Sessions and JWT

  • Pick sessions for a website or app with its own backend, where instant sign-out and simple revocation matter.
  • Pick JWTs when several services or mobile clients must verify users without sharing a session store, and keep them short-lived.
  • Many auth providers combine the two: a short-lived JWT for each request and a long-lived refresh token or session that issues new ones.

The options

More comparisons

Crafted in the dark. Shipped to the world.

Tell us what you are building. You get a private project space with a proposal and a line-by-line quote within a day.