Security and auth / Intermediate / 5 min / Updated
Sessions vs JWTs: stateless tokens and logout
Ban a user and see how long their token still works. Sessions revoke at once but need a store; JWTs skip the lookup but live until they expire.
Start the simulation → Change the load, break a part, watch what happens. Free, no sign-up.
In short
What is JWT vs sessions?
A session is a random id looked up in a store per request; a JWT is a signed token any server can verify on its own.
Why does it matter?
Every request must prove who is calling. JWTs remove the shared lookup; sessions keep instant control over who is logged in.
What is the trade-off?
JWTs cannot be revoked before they expire; sessions add a store lookup and a dependency. Short JWTs plus refresh tokens meet in the middle.
How do you explain it in an interview?
"Short-lived JWT access tokens (5-15 min) verified at the gateway, refresh tokens stored and revocable, a denylist only for urgent bans."
Check yourself
You ban a user whose 15-minute JWT was issued 5 minutes ago. When does the ban take effect without extra work?
Answer: About 10 minutes later, when the token expires. Servers trust any valid signature. Short lifetimes, refresh tokens that can be refused, or a denylist close the gap.
What does a JWT save compared with a server-side session?
Answer: A shared store lookup on every request. Any server verifies the signature locally, so there is no shared store on the hot path and no outage when it is down.
Why pair short access tokens with refresh tokens?
Answer: Access tokens expire fast; the long-lived refresh token can be checked and revoked when renewing. Revocation happens at refresh time, so a ban works within minutes while normal requests stay lookup-free.