Skip to content

Interview PrepAuth designs · Advanced

Authentication Designs ​

These questions reuse the building blocks explained in depth in the identity module. Each answer here is the design: the components, how they connect, and the decisions an interviewer wants to hear, with links to the detail.

35. How would you design a secure login system? ​

The short answer

An auth service owns credentials and sessions. Passwords are hashed with Argon2id; passkeys and MFA are supported, with phishing-resistant options for admins. Login is protected by rate limits per account and IP, breached-password checks, bot challenges after failures, and identical errors for unknown users. On success it creates a server-side session in Redis with a new ID, sent as a __Host-, HttpOnly, Secure, SameSite=Lax cookie, with idle and absolute timeouts. It provides secure password reset, email verification, a devices and sessions page, audit logs and alerts on suspicious logins.

browsergatewayrate limits, WAFauth serviceverify, MFAnew session IDrisk engine: device, IP, velocityusers: Argon2id hashes, passkeysRedis: sessionsaudit log, new-device email__Host-session cookie
Every login passes four gates. Rate limits at the edge, a risk check, the credential check with MFA when needed, and a fresh session. Everything is recorded, and the user hears about unusual sign-ins.
DecisionDetail
Password storageArgon2id, OWASP parameters (bcrypt versus Argon2)
Brute forcePer-account and per-IP limits, growing delays, no permanent lockout (lockout)
MFA and passkeysPasskeys preferred; TOTP; SMS only as fallback (passkeys)
SessionServer-side, cookie only holds the ID (securing cookie login)
RecoverySingle-use hashed reset tokens; revoke all sessions after reset (password reset)

36. How would you design a JWT-based authentication system? ​

The short answer

An auth server issues a short-lived access token, a JWT of 5 to 15 minutes signed with an asymmetric key such as ES256, containing iss, sub, aud, exp, scopes and a kid, plus an opaque, rotating refresh token stored hashed on the server. It publishes public keys at a JWKS endpoint. APIs verify tokens locally, checking algorithm, signature, issuer, audience and expiry. Refresh happens only at the token endpoint, with rotation and reuse detection. Revocation uses refresh-token deletion plus a small deny list or per-user "valid after" time. Browser apps keep tokens server-side behind a session cookie.

PartDesign
Access tokenJWT, 10 minutes, aud per API (JWT claims)
SigningPrivate key in a KMS; public keys in JWKS; rotate by kid (HS256 versus RS256)
VerificationFixed allowed algorithms, issuer and audience (signing and verifying)
RefreshOpaque, hashed, rotated, family revoked on reuse (rotation)
RevocationShort expiry plus deny list or valid-after (revoking JWTs)
Browser storageBack end for front end; no tokens in localStorage (token storage)

37. How would you design OAuth-based login? ​

The short answer

Use OpenID Connect, not plain OAuth, so you get a verifiable ID token. The web app is a confidential client using the authorization code flow with PKCE, state and nonce, through a certified client library. The callback exchanges the code server-side, verifies the ID token, links the external identity to a local user by issuer plus subject, and starts the app's own session. Support several providers through one identity table, link accounts only on verified emails, and handle denial, expired state and provider outages gracefully.

The end-to-end flow, the checks and the code are in OIDC login flow and implementing OAuth login.

The data model that supports several providers:

TableColumns
usersid, email, email_verified, name
identitiesuser_id, issuer, subject, email_at_link_time, created_at; unique on (issuer, subject)
sessionsIn Redis: session_id → user_id, auth_method, auth_time

38. How would you design Google login? ​

The short answer

Register an OAuth client in Google Cloud with exact redirect URIs. On "Sign in with Google", redirect to Google's authorize endpoint with scope=openid email profile, state, nonce and PKCE. In the callback, exchange the code, verify the ID token's signature against Google's JWKS, iss of https://accounts.google.com, aud equal to your client ID, exp and nonce. Find or create the user by Google's sub, trusting email only if email_verified is true, then create your own session. Keep Google's tokens only if you need Google APIs.

The whole flow, with a diagram, is in how Google login works. The design decision worth saying: "Google proves who the user is once; after that, our own session controls access, so revoking our session logs them out of our app regardless of their Google session."

39. How would you design enterprise SSO for multiple applications? ​

The short answer

Put one identity provider, such as Entra ID, Okta or Keycloak, at the centre. Each application registers as a client, using OIDC for new apps and SAML for those that only support it. Users sign in once at the IdP, with MFA and Conditional Access, and each app receives a signed token or assertion and creates its own short session. Groups and app roles flow as claims; SCIM provisions and deprovisions accounts in each app; back-channel logout and short app sessions limit how long access outlives a disabled account. Central audit logs record every sign-in.

The flow across apps is drawn in how SSO works.

DecisionChoice
Protocol per appOIDC by default; SAML where required (SAML versus OIDC)
Session lengthsIdP: a working day. Apps: 30 to 60 minute idle timeout (SSO cookies)
Access per appAssignment at the IdP, by group
Joiners and leaversSCIM provisioning (SCIM)
LogoutBack-channel logout plus short app sessions (single logout)

40. How would you design SAML-based login? ​

The short answer

Your app is the service provider. Each customer's IdP connection stores its entity ID, SSO URL and signing certificates, ideally from a metadata URL. Use SP-initiated login: find the tenant from the email domain, send an AuthnRequest, remember its ID, and receive the response at the ACS URL. Validate with a maintained library: signature over the assertion, issuer, audience, destination, time window, InResponseTo, and one-time use of the assertion ID. Map a stable NameID to the user, groups to roles, create a session, and monitor certificate expiry per customer.

The full design, data model and security points are in designing SAML login, and validation in validating assertions.

41. How would you design multi-tenant SaaS authentication and tenant isolation? ​

The short answer

Every user belongs to one or more tenants, and every request runs in one tenant context, taken from the session or token, never from a client-chosen header. Authentication is per tenant: password and passkeys for small customers, SSO through SAML or OIDC for enterprises, chosen by verified email domain, with an optional "SSO required" setting. Tokens and sessions carry tenant_id. Authorization checks roles within that tenant. Data isolation is enforced in layers: a data-access layer that always filters by tenant, database row-level security, tenant-prefixed cache and storage keys, and separate databases for customers that need them.

asha@acme.examplelogin servicedomain → tenantSSO required?Acme's IdPSAML or OIDCsessionuser + tenant=acmeAPItenant contextdatabaserow-level security
The tenant is decided at login and enforced everywhere after. The email domain picks the tenant and its login method. From then on, the tenant comes only from the session, and the database itself refuses to return another tenant's rows.

Details: tenant isolation, SAML for many tenants and supporting SAML and OIDC.

42. How would you design a secure refresh-token system? ​

The short answer

Refresh tokens are opaque random values, stored hashed with user, client, device, family ID, an idle expiry and an absolute expiry. Every use rotates the token; reusing an old one revokes the whole family and alerts the user. They are sent only to the token endpoint, in an HttpOnly cookie scoped to the refresh path for browsers or the OS keychain on mobile, and can be bound to the device with DPoP. They are revoked on logout, password change and admin action, and listed to the user as active sessions.

The table design, the rotation code and the checklist are in designing a refresh-token system and rotation with reuse detection.

43. How would you design token revocation at scale? ​

The short answer

Make revocation mostly unnecessary with short access tokens, 5 to 15 minutes, and revoke the refresh token in the database. For immediate cut-off, keep a tiny deny list of revoked token IDs with entries that expire when the token would have, plus a per-user "valid after" timestamp for "log out everywhere". Distribute both by pushing revocation events to every service, which keeps them in memory, with Redis as the shared fallback. Keep introspection for the few highest-risk APIs, and rotate the signing key for a key compromise.

The diagram and the numbers are in revocation at scale.

44. How would you design authentication for microservices? ​

The short answer

Authenticate users once at the edge: the API gateway or a BFF validates the user's token or session. Inside, every call carries two identities: the calling service, proven by mTLS from a service mesh or a client-credentials token with an audience, and the end user, carried as a signed token, ideally exchanged for a narrower, audience-specific token per hop. Each service verifies both itself and makes its own authorization decision; nothing is trusted because it comes from inside the network, and plain headers such as X-User-Id are never accepted as identity.

The two-question picture is in how services authenticate each other; token exchange is in token exchange; the end-to-end architecture is in securing microservices.

45. How would you design API Gateway authentication? ​

The short answer

The gateway is the first, coarse check. It terminates TLS, validates the incoming credential, a JWT by signature, issuer, audience and expiry against cached JWKS, or an API key by hashed lookup, or a session through the BFF, and rejects bad requests with 401 before they reach services. It applies rate limits and quotas per client, strips any client-sent identity headers, and forwards a verified identity to services, as the original token or a newly minted internal token. Fine-grained authorization stays in the services; the gateway never becomes the only line of defence.

Gateway doesService still does
Verify token signature, issuer, audience, expiryVerify the token again, or the internal token
Check required scope for the routeCheck this user may act on this record
Rate limits per API key or userBusiness rules
Remove client-sent X-User-* headersNever trust identity from headers
Log every request with a trace IDAudit sensitive actions

Gateway responsibilities in general: API gateways.

46. How would you design a centralized IAM platform similar to Entra ID or Okta? ​

The short answer

The core is a multi-tenant directory of tenants, users, groups, applications and credentials, and a token service implementing OIDC, OAuth 2.0 and SAML. Around it: an authentication service supporting passwords, passkeys and MFA; a policy engine for conditional access, evaluating user, device, location and risk at each sign-in; sessions with SSO cookies; federation to external IdPs; provisioning with SCIM; an admin and self-service portal; and audit logs. It must be extremely available, multi-region, with signing keys in HSMs, strict tenant isolation, and rate limiting against credential attacks.

users, appsdevicesedgerate limitsbot defenceauthentication + MFAtoken servicepolicy engine, risksessions, SSO cookiesdirectorytenants, usersgroups, appsHSM keysfederationSCIMaudit
A directory, a token service and a policy brain. Every sign-in passes the edge, is authenticated, is checked against policy, and ends with tokens signed by keys that never leave hardware. Federation, provisioning and audit hang off the same directory.
RequirementDesign
AvailabilityMulti-region active-active for token issuing; the directory replicated, with writes in a home region per tenant
LatencySigning keys cached as handles; JWKS on a CDN; tokens verified locally by apps
IsolationTenant ID on every record and key; per-tenant rate limits so one tenant cannot starve others
SecurityHSM-backed signing keys, rotated; admin actions need phishing-resistant MFA; full audit
AttacksCredential stuffing defences, consent-phishing review, anomaly detection
ExtensibilityCustom claims, hooks, and per-tenant branding

47. How would you implement enterprise identity federation? ​

The short answer

Federation lets users from a partner's or customer's own IdP access your systems with their home accounts. Establish trust by exchanging metadata, entity IDs, endpoints and signing certificates, for SAML, or issuer and JWKS for OIDC. Configure claims mapping: which attribute is the stable user ID, which become email, name and groups, and how groups map to your roles. Choose provisioning: just-in-time at first login or SCIM. Restrict which domains each trusted IdP may assert, monitor certificate expiry, and log federated sign-ins separately so you can audit partner access.

StepDetail
TrustExchange metadata; pin issuer and certificates per partner (federation)
Identity keyPartner's persistent NameID or sub, never only email
ClaimsMap and transform attributes per partner (claims transformation)
AccountsJust-in-time or SCIM (JIT)
GuardrailsA partner's IdP may only assert users in its own verified domains
OperationsCertificate expiry alerts, a test login per partner, audit of partner sign-ins

Combine chapters into one PDF

Pick the chapters you want. They print in the order you pick them.

Interview Prep
System Design
The method
Case studies
Auth designs
Scenarios
Other topics
Nothing picked yet