← Back to TIL

jwt

Jan 15, 2026

authjwtsecuritybackend

what is a jwt?

jwt (json web token) is a self-contained, signed token carrying authentication claims.

it has three parts:

header.payload.signature

the server verifies the signature and trusts the payload without looking up a session.

why use it?

jwt enables stateless authentication:

  • no server-side session storage
  • no db/redis hit per request
  • easy horizontal scaling
  • works well across services and platforms

comparison

approachwhere state liveslookup per requestrevoke instantlyscales easilycommon failure mode
db sessiondatabaseyesyesmehdb becomes auth bottleneck
redis sessionredisyesyesdecentredis outage = logout storm
jwtclient tokennono (until exp)yesleaked token lives until expiration

practical take

  • db/redis sessions optimize control
  • jwt optimizes distribution
  • jwt is not “more secure”, just different tradeoffs