CodeOath
← All posts
Auth & Security60 min total · 19 parts

OAuth 2.0 and JWT Explained: How "Login with Google" Actually Works

Contents — Part 16 of 19: Sessions vs. Tokens: Two Different Models
Part 16 of 19 · ~1 min

Sessions vs. Tokens: Two Different Models

It's worth stepping back and comparing token-based auth (JWTs) against the older, still extremely common server-side session model directly, because interview questions often frame this as "which is better" when the honest answer is "different trade-offs for different architectures."

Server-side sessionJWT / token-based
Where state livesServer (database, Redis) — cookie holds only an opaque IDEntirely in the token itself — server verifies, doesn't look anything up
RevocationInstant — delete the session recordHard — valid until exp, absent extra infrastructure
Scaling across serversNeeds a shared session store (Redis, sticky sessions)Naturally stateless — any server with the verification key can validate it
Payload size on the wireSmall (just an opaque ID)Larger — the full payload travels with every request
Best fitA single application with its own loginMultiple services/APIs needing to verify identity without a shared database

Neither model is a strict upgrade over the other — a JWT's biggest practical advantage (statelessness, no database hit to verify a request) is also the direct source of its biggest practical weakness (no instant revocation), and plenty of production systems land on a hybrid: a short-lived stateless JWT for API calls, backed by a server-side, instantly-revocable session or refresh token controlling whether new ones keep getting issued.