Authentication
who are you โ sessions vs JWTsAuthentication proves identity. After login, the server issues something the client presents on later requests, and the two dominant approaches differ in where the state lives.
SESSION + COOKIE JWT (JSON Web Token)
server stores session, sends an ID server signs a token holding the claims
client โcookie(id)โโถ server client โtokenโโถ server
server looks up id in session store server verifies the SIGNATURE, no lookup
โถ state on the SERVER โถ state in the TOKEN (stateless)
โถ revoke = delete the session (easy) โถ revoke = hard (valid till it expires)
| Sessions | JWT | |
|---|---|---|
| State | Server-side store | In the token, stateless |
| Scaling | Needs a shared session store | Any server verifies alone |
| Revocation | Easy โ delete the session | Hard โ valid until expiry |
| Best for | Classic web apps | APIs, microservices, mobile |
Authorization
what are you allowed to doAuthentication is who you are; authorization is what you're allowed to do. Different problems, often conflated. A valid login (authN) doesn't mean you can delete another user's data (authZ). RBAC โ role-based access control โ is the default model: assign users roles, grant permissions to roles, check the role on each action.
Encryption
in transit, at rest, and hashingTwo states to protect, plus one thing that isn't encryption at all.
TLS on every connection, including service-to-service. In a zero-trust design, internal calls use mTLS โ both sides present certificates, so services mutually authenticate and the internal network isn't assumed safe (TLS).
Disk and database encryption protect data if the storage is stolen. For the truly sensitive โ SSNs, card numbers โ add field-level encryption so a single leaked field is useless without the key.
Secrets Management
keys, tokens, and where they don't goAPI keys, database passwords, and signing keys are secrets, and they do not belong in code or committed env files โ one leaked repo and they're public forever. Store them in a dedicated secret store โ Vault, or a cloud KMS โ that services fetch from at runtime with tight access control, and rotate them periodically so a leaked secret has a short useful life.
The Perimeter
defense in depthNo single control is enough โ you layer them so one failure doesn't mean a breach. That's defense in depth.
| Control | Guards against |
|---|---|
| Rate limiting | Abuse, credential stuffing, scraping (Scaling) |
| Input validation at the edge | Injection, malformed payloads โ reject early |
| Least privilege between services | A compromised service can't reach everything |
| Defense in depth | One bypassed layer isn't game over |
Quick Reference
sessions vs JWT, and the lines to say| Sessions | JWT | |
|---|---|---|
| State | Server-side | In the token |
| Revocation | Easy (delete session) | Hard (short expiry + refresh) |
| Scaling | Shared session store | Stateless verify |
| Fits | Web apps | APIs, mobile, microservices |
| Security lines to say during a design |
|---|
| TLS everywhere, mTLS between services in zero-trust |
| Passwords hashed with bcrypt/argon2, never encrypted |
| AuthZ at the gateway (coarse) and service (fine-grained) |
| Secrets in a vault, rotated, never in code |
| Rate limiting + input validation at the edge; least privilege throughout |