Skip to content
SD-35 · System design

Design a Login and Authentication

Asked at Senior level45 minutes
Our answers stay hidden until you reveal them.

Design the login and authentication system for a large website. People sign up with an email and a password or with a social account, log in, stay logged in for weeks on each device, and can log out of one device or all of them. They can turn on two-step verification and reset a forgotten password. Every page request must know, quickly and correctly, which user is asking.

The site has 100 million accounts and 20 million daily users, which makes about 150,000 page requests a second at peak, each one needing a session check. Logins are rare by comparison, about 150 a second, but each must run a deliberately slow password hash. Attackers try leaked email and password pairs from other sites at 20 times the normal login rate. The hard parts are a session check that is fast enough for every request but can still be revoked at once, a login path that stays up under attack, and stopping account takeovers without locking real users out.

Good questions to ask first

Decide what you would assume for each before you look at ours.

  1. 1How do people log in?
  2. 2How long does a login last?
  3. 3Must logout and password changes take effect at once?
  4. 4Do we need two-step verification?
  5. 5Web only or apps too?
  6. 6How big is the attack problem?
  7. 7Do other services check identity?
  8. 8Is single sign-on for other companies in scope?

How to spend the 45 minutes

  1. 5minPart 1: Requirements: login methods, session length, revocation
  2. 5minPart 2: Estimates: checks vs logins vs attacks
  3. 5minPart 3: API and data model
  4. 15minPart 4: Architecture, stage by stage
  5. 15minPart 5: Passwords, sessions, stuffing and MFA
Sketch your own design: boxes, arrows and the numbers that matter. Then compare it with ours.Break it in the labVisual walkthrough