Design the login service for a company with 10 million users and a dozen backend services. Users sign in with an email and password or through Google or GitHub (OAuth). After login the service issues a short-lived access token that other services verify on their own, plus a refresh token to keep the user signed in. Attackers regularly try leaked passwords against the login endpoint. At peak there are about 400 login and token-refresh requests per second.
Functional requirements
Sign up and log in with email and password
Log in with Google or GitHub through OAuth
Issue a 15-minute access token and a longer-lived refresh token
Revoke a user's refresh tokens on logout or password change
Non-functional requirements
Passwords are never stored or logged in plain text
Brute-force and credential-stuffing attempts are throttled
Other services verify tokens without calling the login service
Logins complete in under 1.5 seconds at p95, including OAuth
Constraints and scale
10 million users
400 login and refresh requests per second at peak
Signing keys must be rotated every 90 days without logging users out
You will practise
Store credentials safely with a slow, salted password hash
Issue signed tokens and verify them without a central lookup
Protect a login endpoint from brute-force attacks and keep secrets out of code
Show 2 hints
Why is a fast hash like SHA-256 a poor choice for passwords?
If access tokens are verified locally, how does a revoked user eventually lose access?