KatInterview

Design a Secure User Registration and Authentication Service

System DesignModel answer
MediumModel answerSystem Designauthenticationsecurityapi-design

Last updated

Architect an in-house email/password signup and login system emphasizing secure password storage, API contract design, session state management, and edge-case handling.

Design an internal authentication microservice supporting primary email and password registration and login functionality. Third-party identity frameworks (such as OAuth2, OIDC, or social authenticators) are out of scope. High-concurrency distributed scaling is not required—assume a single monolithic database instance is sufficient—but your architectural design must prioritize robust API modeling, clean database normalization, secure credential handling, and reliable session control.

Key Focus Areas

  • Core Requirements: Functional endpoints for account creation, credential validation, session retrieval, and explicit logout.
  • Data Persistence: Database schemas, key fields, constraints, and relational mappings.
  • Credential Protection: Hashing algorithms, salting techniques, memory hardness, and timing attack defenses.
  • Session Lifecycle: Trade-offs between opaque server-managed tokens and stateless tokens (JWTs), including expiration, storage mechanisms, and revocation strategies.
  • Input Validation & Security Edge Cases: Password policies, anti-enumeration tactics, rate-limiting, and concurrent registration race conditions.

System Assumptions & Constraints

  • Infrastructure: All HTTP traffic is protected via TLS terminating upstream (e.g., at a load balancer or ingress proxy).
  • Scope Limitations: Advanced identity workflows—such as MFA enforcement, password recovery links, email verification tokens, and account deletion protocols—can be treated as out of scope, provided your architecture indicates where they cleanly integrate.

Hints

Hint 1

Consider how database-level constraints handle race conditions during simultaneous user registration with identical email addresses.

Hint 2

Evaluate the operational trade-offs of storing sessions in a database (opaque tokens) versus relying on self-contained signed payloads (JWTs), especially around revocation.

Hint 3

Ensure password hashing algorithms are chosen specifically for computational and memory hardness (e.g., Argon2id or bcrypt) rather than throughput speed (e.g., SHA-256).