Jwts Identity Without A Session Table
A JWT answers a scaling problem this whole course quietly assumed away, one shared server checking one shared session table, by carrying identity in the token itself.
The last post ended on the question this course hasn't touched yet: trusting an identity without a database to check it against. That's exactly what a JWT is built to do, and understanding why anyone would want that starts with a problem this entire course has quietly been assuming away.
The Assumption Baked Into Everything So Far
Every session example up to this point assumed something specific: one web server, or at least one shared session database, that any request can query to check who's logged in. That's a completely reasonable assumption for a single app, and it's genuinely fine for a lot of real systems.
It starts breaking down at a certain kind of scale, and not the vague, hand-wavy kind of scale people invoke to justify overengineering.
- Authentication becomes its own service, entirely separate from the app that actually uses it.
- Multiple services live on different origins, and all of them need to verify who's making a request.
- A user is logged in simultaneously across a phone app, a tablet app, and a browser, and all of them need to agree on who that user is.
A shared session database becomes a real coordination problem at that point, not a theoretical one. This is a legitimate architecture and scaling problem, not something to reach for just because a token sounds more modern than a cookie.
The Core Idea
What if there were no server-side session to look up at all? What if the token itself just carried everything needed to know who someone is and what they're allowed to do, and whoever received it could verify nobody had tampered with it, without ever touching a database?
That's a JSON Web Token, pronounced "jot." It has three parts.
- A header, describing which algorithm was used to sign it.
- A payload of claims, arbitrary data like a username, roles, or permissions, the actual "what can this person do" information.
- A signature, proving the first two parts weren't changed after the token was issued.
eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoicGV0ZXIiLCJyb2xlIjoiYWRtaW4ifQ.k3jFa9...
header (algorithm) payload (claims) signatureThe Same Idea You've Already Seen, Applied Differently
This is the exact same mental model from signing cookies earlier in this course: value plus secret, mixed together, producing something the receiving side can independently recompute and check. A JWT applies that identical idea to a self-contained claims payload instead of a single plain cookie value.
The tamper-detection logic behind that signature is also the same idea, applied differently, as Subresource Integrity's hash verification from the CSP chapter: if the thing you received doesn't match what the signature says it should be, you don't trust it. Different mechanism, same underlying question: did this actually arrive exactly the way it left?
ExpandA traditional session lookup querying a shared database next to a JWT's self-contained claims and signature, needing no lookup at all.
Why This Is Genuinely Useful
Since there's no session lookup required, any service holding the same shared secret can independently verify a token's authenticity, with no database call and no coordination with any other service.
That's exactly what makes JWTs a real fit for microservice architectures, and for decoupling an authentication system from the applications that actually consume its tokens. It's also what makes passing an Authorization header a workable pattern instead of relying on a shared cookie across origins that don't actually share a site, since cookies were never designed to cross real origin boundaries cleanly.
The Trade-off That Matters Most
A database-backed session can be revoked instantly, just by deleting a row. A JWT cannot.
Once a JWT is issued and signed, it stays valid until it actually expires, no matter what happens on the server after that. If a token gets stolen, or a mistake gets made somewhere, there is no "delete the session" button. The only option is waiting out the expiration window.
This is a genuine, serious limitation, worth taking seriously on its own terms rather than treating it as a footnote you skim past on the way to the fun architecture diagram.
The Mistake That's Easy to Make by Accident
The verifying side of a JWT has to check that the token was actually signed with the algorithm it claims, and the algorithm the app actually expects. Skipping that check is a real, documented category of JWT vulnerability, one where an attacker can force a weaker or different algorithm through simply because nothing on the receiving end confirmed what it was supposed to be checking against.
This usually isn't a deliberate design choice gone wrong. It's a missing line of verification code, easy to skip when a JWT library's defaults make things "just work" without you ever explicitly stating the algorithm you expect.
What This Sets Up
A JWT solves the lookup problem cleanly. It doesn't answer the much more practical question every team ends up asking the moment they actually try to use one: where does this thing actually live in the browser?
That's not a small detail, and getting it wrong quietly reopens problems this course already spent real time closing.
The Essentials
- JWTs solve a real scaling problem, coordinating identity across multiple services, origins, or devices without one shared session database.
- A JWT has three parts: a header naming the algorithm, a payload of claims, and a signature proving neither was tampered with.
- The signature reuses the value-plus-secret mental model from signed cookies, applied to a self-contained claims payload instead of a single value.
- Verifying a JWT needs no database lookup, which is what makes it genuinely useful across microservices and decoupled auth systems.
- A JWT cannot be revoked once issued. It's valid until it expires, no matter what happens on the server afterward.
- Failing to pin and verify the signing algorithm is a real, documented vulnerability, usually caused by a missing check rather than a deliberate decision.
Next up: the practical question every JWT eventually forces, where it actually lives once it's sitting in the browser.
Further Reading and Watching
- JSON Web Tokens (JWTs) Explained: a walkthrough of the three-part structure and how the signature gets verified.
- Introduction to JSON Web Tokens: the official reference on JWT structure, claims, and signing algorithms.
Keep reading