KatInterview

Building a Secure Login and Session Service for a Cloud App

System DesignModel answer
MediumModel answerSystem Designauthenticationsessionssecurity

Last updated

Design a login and session service for web and API clients using email and password, extensible to federated identity, with strong credential handling, abuse defenses, and a plan for 10x growth.

You are asked to design the identity and login layer for a multi-tenant cloud product. Today people sign in with an email address and a password. Later, the business wants to let customers sign in through external identity providers without a rewrite.

Walk through a design that covers:

  • The login flow and the public APIs (sign-up, login, token refresh, logout, password reset, and a future external-provider flow)
  • The storage schema and your choice of database
  • How credentials are protected at rest and in transit
  • The session lifecycle: issuance, validation, rotation, expiry, and revocation
  • Backup, restore, and disaster recovery for identity data
  • A staged plan for handling ten times today's traffic

Assumptions

  • Both browsers and programmatic API clients must be supported.
  • Authentication answers "who is this?". Product-specific authorization is a separate concern, but it must receive the identity in a safe, verifiable form.
  • Passwords must never be recoverable from what you store.
  • Clients may retry requests, sessions may need to be revoked, and attackers will attempt credential stuffing.
  • Availability matters, but you must not weaken credential checks to stay up during an outage.

Questions worth raising with the interviewer

  • Which login methods, compliance requirements, and session lengths are needed?
  • Does revocation need to take effect instantly everywhere, or is a short delay acceptable?
  • Is multi-factor authentication mandatory for everyone or only for sensitive actions?
  • What recovery point and recovery time objectives apply to identity data?

Hints

Hint 1

Start by drawing trust boundaries: untrusted clients, an edge layer (TLS, WAF, rate limiting), the auth service, its datastore, and downstream product services that only ever see signed identity assertions.

Hint 2

Decide what a session is: short-lived signed access tokens plus a longer-lived, rotating, server-tracked refresh token gives you cheap validation and a real revocation point.

Hint 3

Treat abuse as a first-class requirement: per-account and per-IP throttling, uniform error messages, breached-password checks, and audit logs. Then describe how each tier (stateless auth nodes, cache, primary and replicas, partitioning) scales independently.