Stateful vs Stateless Authentication
You'll learn the fundamental difference between server-side session storage and self-contained token-based authentication.
The Core Distinction
In web authentication, you have two primary approaches for remembering that a user is logged in across requests:
Stateful authentication means the server stores session data. When you log in, the server creates a session record (often in a database or memory store) and sends you a session ID cookie. On each request, you send that ID, and the server looks up your session to verify you're authenticated. The server "remembers" you.
Stateless authentication means the server stores nothing. Instead, you receive a self-contained token (like a JWT) that includes all necessary information and is cryptographically signed. On each request, you send the token, and the server verifies its signature and reads the data inside—no database lookup needed. The token itself "proves" who you are.
The Trade-Offs
Think of stateful like a coat check: you get a ticket (session ID), but the coat check person must look up which coat belongs to your ticket every time. Stateless is like wearing your coat—everything you need is with you, no lookups required.
Stateful pros: Easy to invalidate sessions immediately (just delete the server record), simpler tokens (just random IDs).
Stateful cons: Requires server-side storage, harder to scale across multiple servers, database dependency.
Stateless pros: No server storage needed, scales horizontally easily, works great for APIs.
Stateless cons: Tokens can't be truly invalidated until they expire, tokens can grow large if they contain lots of data.
Key Takeaway: Stateful authentication stores session data on the server and uses session IDs, while stateless authentication uses self-contained, signed tokens that require no server-side storage between requests.