LOAD-BEARINGfree
High-level designTier 12 · unit 1 of 11 · 14 min read

Authentication: proving who is calling

Every tier so far quietly assumed the caller was who they claimed to be. Drop that assumption and much of your architecture changes shape. Authentication answers exactly one question — who is making this request? — and it is a different question from what they are allowed to do, which is the next lesson. Collapsing the two into one is the most common security design error there is.

Sessions and tokens: where does the truth live?

Two designs, and the difference is where the server keeps the fact that you logged in.

A session puts the truth in your datastore. The client holds an opaque id and every request looks it up. Revoking is trivial — delete the row — but every request now pays that lookup, and the store becomes a dependency of literally everything.

A signed token puts the truth inside the token. The server verifies a signature and reads the claims without asking anyone. No lookup, no shared dependency, scales beautifully — and you have just built something you cannot take back. A signed token stays valid until it expires, whether or not you revoked that user thirty seconds ago.

The revocation tradeoff
Opaque session idrevoke instantly · lookup per request
Signed token, long lifeno lookup · revocation is a fantasy
Short token + refreshrevoke within one lifetime · store on refresh only

The third row is where most production systems land: an access token that lives minutes, and a refresh token that lives days and is checked against a store. You pay one lookup per refresh instead of one per request, and your revocation window becomes a number you can state rather than a hope.

What a token has to say

A token carries claims: who the subject is, who issued it, who it is for, and when it stops being valid. The audience claim is the one people omit and later regret — without it, a token minted for your low-value analytics service is a perfectly valid token at your payments service. Every service must check it was the intended recipient, not merely that the signature verifies.

The same care applies to the algorithm. Verify against the key you expect, using the algorithm you expect. Trusting whatever the token's own header claims it was signed with is how systems end up accepting tokens signed with nothing at all.

Delegation is not identity

A delegation protocol answers "this user permits application X to act on their behalf, within this scope". That is genuinely useful and it is not the statement "this user is Ananya" — establishing identity needs a layer built deliberately on top. Treating a raw delegation flow as a login is a real and repeatedly exploited class of bug: the application proves that somebody authorised it, then infers which user from context that an attacker may control.

The trap

Putting the user id somewhere the client controls. A header, a query parameter, a field in the body — anything the caller supplies is a claim, not an identity, and any caller can change it. Identity comes only from something the server verified on this request: a signature it checked, or a session it looked up. If an internal service reads X-User-Id and believes it, then anyone who can reach that service is everyone.

Authentication happens once, at the edge — but the result has to travel inward safely. The next two lessons handle that: turning "who" into "may they", and giving services identities of their own so the question can be asked between machines too.