JWT vs Session Cookies: Pick One and Move On

JWT vs Session Cookies: Pick One and Move On

Paste a JWT you assembled five minutes ago into a decoder and it will report a valid structure. Not a bug: the tool checks the three-part shape and decodes base64url; it does not verify the signature. Most JWT-versus-session arguments go wrong here.

Two designs, one job

Both answer the same question: who is making this request? A session cookie carries an opaque random ID; the server looks it up in a store and finds the user record. A JWT carries the claims themselves in a signed envelope; the server verifies the signature with a key and trusts the contents without a lookup.

The payload is base64url-encoded JSON, not encrypted. Anyone holding the token can read sub, exp, and any roles you put in it. Never put secrets there.

Side by side

Question Session cookie JWT
What the client holds random session ID header, payload, signature
Where user state lives server store inside the token
Logout / revoke one login delete the record, immediate hard; needs a denylist or token rotation
Extra infrastructure shared store across servers key distribution, short expiry
Readable by the client no, opaque yes, payload is plain JSON
Typical size tens of bytes hundreds of bytes to kilobytes
Best fit browser sessions for a web app short-lived access tokens, service-to-service calls

Three arguments that aren’t as strong as they sound

“JWT is stateless, so it scales better.” Verification scales; revocation does not. Statelessness means you cannot delete a session — you wait for expiry or you keep a denylist, which is state with a different name.

“Sessions don’t scale.” A key-value lookup per request is cheap, and it is rarely the bottleneck. The shared store adds a moving part, not a crisis.

“JWT is secure because it is signed.” A signature proves who issued the token. It does not prove the user should still have access, and it does nothing if the payload was readable all along.

How to choose, and how to debug

For a normal browser login, use a session cookie: HttpOnly, SameSite, secure flag, and a server-side store you can delete from. For machine-to-machine calls or short-lived access tokens in a distributed system, use a JWT with a short exp and a refresh flow.

When a token gets rejected, the JWT decoder is the fastest way to see exp, aud, and iss. Just remember what the status line means: structure parsed, signature not checked. Expiry validation and signature verification are your server’s job.

If logging someone out has to be instant, you need server-side state. JWT does not remove that requirement — it moves the state into a denylist you now have to build and operate.