Infrastructure primitives
Login and sessions - who you are, on every request
How a password becomes a session, and what changes when the session is a signed token nobody can revoke.
What this board gets wrong on purpose
The tension
Access tokens are JWTs that every service checks on its own with a public key - that is what makes each request cost microseconds, and it is exactly why they cannot be taken back. Logout deletes the session row and its refresh token, but the access token already in the browser keeps working for up to 15 minutes, and so does a stolen one; "change password" and "sign out everywhere" have the same 15 minute hole. Shortening the lifetime moves load onto the refresh endpoint, and adding a denylist puts a shared lookup back on every request, which is the thing JWTs were chosen to avoid. Separately, failed logins are limited per account, so anyone who knows your email can lock you out on purpose.
Practise this as an interview
Take Login and sessions - who you are, on every request as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.
Start here
Why this design
Every product with accounts has this system, and most security incidents involve some part of it: weak password storage, credential stuffing, a session that outlives a logout, a token that cannot be revoked. Interviewers use it to check that you know how passwords are stored, the difference between authenticating once and checking a credential on every request, and the real trade between server-side sessions and signed tokens - not the blog-post version where JWTs are simply better.
What you will learn
- How a password is stored (argon2id or bcrypt, with a per-user salt) and why the hash is slow on purpose.
- Why rate limiting must happen BEFORE the hash: one credential-stuffing attack can need hundreds of CPU cores otherwise.
- Opaque session ids against signed tokens: a lookup on every request against no lookup and no revocation.
- The hybrid most systems use: a 15 minute access JWT plus a rotating refresh token kept server side.
- Cookies done right: HttpOnly, Secure, SameSite - and what each one stops.
How to read this board
- LOG IN · ONCE across the top: user, browser, the login service hex, the password hasher and the token signer.
- STORES on the right: users, failed login attempts, and sessions with their refresh tokens.
- EVERY REQUEST across the bottom: the API server hex checking tokens locally, the services behind it, the refresh endpoint and the red logout.
- Press play, then read pages 1 to 6, then the DATA MODEL tables.
- The conversation to have: what exactly happens to a stolen access token after the user logs out, and what you would pay to close that window.
1 · Requirements
Functional
- Sign up with email and password; log in; log out.
- Stay logged in across browser restarts for up to 30 days of inactivity.
- Every API request identifies the user without asking for the password again.
- Several devices at once, each a separate session the user can see and end.
- "Sign out everywhere" and password change end all other sessions.
- Lock out guessing: limit failed attempts by IP and by account.
Non-functional
- Checking a credential on a request: under 1 ms, and no single shared store on the hot path if it can be avoided.
- Login: under 500 ms including the deliberately slow hash.
- Passwords are never stored or logged in a recoverable form.
- A logout or revocation takes effect within a stated bound - this board says 15 minutes.
- Login availability 99.9 percent; request checking 99.99 percent (it is in front of everything).
Out of scope
- Social login and SSO (OAuth / OIDC with another provider) - the same session machinery after a different first step.
- MFA flows in detail. The login service is where they plug in.
- Authorisation (what a user may do) beyond carrying their id and roles in the token.
The rest of this board
Available on Tier Slate
This page publishes the question. The answer — 5 more written pages, an 8-step narrated walkthrough and a 4-table schema — is the board itself, and it opens in Tierslate.
- 5written pages
- 8walkthrough steps
- 4tables27 columns
5 pages behind this one
- Capacity estimation
- Storage estimation
- Availability
- How it works
- Deployment plan
More boards
The building blocks an interview asks you to build from scratch.
- URL shortener - one write, a million reads
- Distributed cache - the ring, and what a node leaving costs
- Key-value store - quorums, and where the consistency knob sits
- Rate limiter - token bucket, and where the counter lives
- Unique ID generator - 64 bits, and two facts nobody can check
- Web crawler - a frontier, and the trap of crawling forever
- Pastebin - a blob store with a short name
- Load balancer - spreading traffic, and noticing who is dead
- API gateway - one front door for many services
- Feature flags - a config change that ships like code
- Secrets manager - the one store everything trusts
- DNS - the cache that runs the internet
- Distributed cron - exactly one runner at nine o'clock
- Background job queue - at least once, and the retry that doubles it
- Code execution sandbox - running a stranger's program
- Distributed log - Kafka from the partition up
- Consensus - a leader, a log, and a majority
- Object storage - eleven nines from cheap disks