Authorization (AuthZ) — Check permissions. Can this user access this resource? Admin? Read-only?
Sessions vs Tokens
Server-Side Sessions
User logs in with credentials
Server creates a session, stores it in memory or a database
Server sends back a session ID in a cookie
On each request, the server looks up the session
Pros: Server can revoke sessions instantly. Session data stays server-side.
Cons: Hard to scale across multiple servers (need shared session store). Stateful.
Tokens (JWT)
User logs in with credentials
Server creates a signed token, sends it to the client
Client stores the token and sends it on each request
Server verifies the signature — no database lookup needed
Pros: Stateless. Easy to scale. Works across services.
Cons: Cannot revoke instantly (token is valid until expiry). Token contains data that can get stale.
JWT Structure
A JWT has three parts separated by dots: header.payload.signature