CMD Guide
HomeSystem DesignAuthorization

Authentication vs Authorization

Authentication vs Authorization

These two words sound alike, get abbreviated to the same three letters (authn and authz), and live next to each other in every login flow — so people conflate them constantly. But they answer two different questions, and confusing them is the root cause of a huge fraction of real-world security breaches.

Authentication (authn) asks: "Who are you, and can you prove it?" It establishes identity. When you type a username and password, tap a fingerprint sensor, or click a magic link in your email, you are authenticating.

Authorization (authz) asks: "Now that I know who you are, what are you allowed to do?" It establishes permissions. Being logged in as alice@corp.com does not mean you can delete the production database or read another user's medical records — that is a separate decision.

The mental model: authentication is showing your passport at the airport (proving you are who you claim). Authorization is the boarding pass and visa that decide which gate, which plane, and which country you may actually enter. One identity, many different permission decisions.

How it works, precisely

Authentication verifies a credential against something the system trusts. The classic taxonomy is three factors: something you know (password, PIN), something you have (phone, hardware key, TOTP app), and something you are (fingerprint, face). Requiring two different factors is MFA. The output of successful authn is a proven principal — an identity the rest of the system can rely on. That identity is usually persisted as a session (a server-side record keyed by a cookie) or a token (a signed JWT the client carries and the server verifies statelessly).

Authorization takes that established identity plus the requested action and resource, and evaluates a policy to return allow/deny. The dominant models:

The critical ordering rule: authn always precedes authz. You cannot decide what an identity may do before you have established the identity. HTTP encodes the distinction directly: 401 Unauthorized actually means unauthenticated ("log in first"), while 403 Forbidden means authenticated but not authorized ("I know who you are; you still can't do this").

Worked scenario: a document API at scale

Imagine a SaaS docs product serving 50,000 QPS at peak. A user opens GET /docs/9812. Two distinct checks happen on that single request:

1. Authn (once per session, cached thereafter). The browser sends a cookie carrying a JWT. The API verifies the signature with the identity provider's public key. Signature verification is pure CPU — roughly 50–200 µs — with no network hop, which is exactly why stateless tokens scale: at 50k QPS you are not hitting a session store 50,000 times a second. The token's exp claim (say 15 minutes) bounds its lifetime; a refresh token silently mints a new one.

2. Authz (every single request). Now the service must decide: may alice read this specific doc 9812? With ReBAC (Zanzibar-style), it queries a permissions service: "does alice have viewer on doc:9812?" That is a graph lookup — Google's Zanzibar paper (Pang et al., USENIX ATC 2019) reports serving roughly 10 million authorization QPS at <10 ms p95 globally, thanks to aggressive caching of relationship tuples. With plain RBAC the check is often local ("is alice's role in {viewer, editor, admin}?") and takes microseconds, but it cannot express "only her docs."

The load asymmetry is the key insight: you authenticate a user once and reuse that identity for millions of requests, but you authorize every request — so the authz path is the one you optimize, cache, and worry about under load.

Trade-offs — when to use which, and which alternative

These are not competing choices; you always need both. The real trade-off decisions are within each half:

Sessions vs stateless tokens (an authn choice). Server-side sessions are trivially revocable — delete the row and the user is instantly logged out — but every request costs a session-store lookup. JWTs are self-contained and cheap to verify at massive scale, but hard to revoke before expiry: a stolen token is valid until exp. Use sessions when instant revocation matters (banking, admin consoles) or traffic is modest. Use JWTs for high-throughput, multi-service, or mobile APIs where a per-request DB hit would dominate cost — and keep expiry short (5–15 min) to bound the blast radius.

ACL vs RBAC vs ABAC vs ReBAC vs PBAC (an authz choice). Use ACL for tiny per-resource guest lists where the owner is obvious ("who can see this doc?"). Use RBAC when permissions are coarse and stable (a handful of roles) — it is the simplest thing that works and is trivially auditable. Reach for ABAC when decisions depend on context or resource attributes (region, time, data classification) and RBAC would explode into a combinatorial mess of roles ("role explosion"). Reach for ReBAC when the core question is ownership/sharing in a graph — Google Docs sharing, GitHub repo access, folder inheritance — where relationships, not static roles, define access. Reach for PBAC when rules must be versioned, centrally authored, and applied consistently across services (OPA, AWS IAM). Don't reach for ABAC/ReBAC/PBAC prematurely: they add a policy engine and operational surface you must run and reason about.

Pitfalls an interviewer probes

Key takeaways

In the worked scenario, after the gateway validates the user's identity, it forwards the request context to an OPA sidecar; OPA evaluates the Rego policy and returns allow/deny before the request ever reaches the order service.

🤖 Don't fully get this? Learn it with Claude

Stuck on Authentication vs Authorization? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Authentication vs Authorization** (System Design) and want to truly understand it. Explain Authentication vs Authorization from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Authentication vs Authorization** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Authentication vs Authorization** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Authentication vs Authorization** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes