| Users/Requests | Authentication Load | Token Management | Security Concerns | Infrastructure Impact |
|---|---|---|---|---|
| 100 users | Low request rate, simple validation | In-memory token store or stateless JWT | Basic rate limiting | Single auth server sufficient |
| 10,000 users | Moderate request rate, more token checks | Distributed cache for token revocation | Implement throttling, monitor suspicious activity | Load balancer with multiple auth servers |
| 1,000,000 users | High request rate, token validation bottleneck | Stateless JWT preferred, cache public keys, token introspection service | Advanced security: anomaly detection, IP blacklists | Horizontal scaling, CDN for static keys, dedicated auth microservices |
| 100,000,000 users | Very high concurrency, global distribution | Global token key distribution, sharded token revocation, multi-region caches | Zero-trust, continuous authentication, automated threat response | Multi-region clusters, edge authentication, global load balancing |
API authentication (OAuth, JWT, API keys) in HLD - Scalability & System Analysis
The first bottleneck is the authentication server CPU and token validation process. As user requests grow, the server must validate tokens (JWT signature checks, OAuth token introspection, API key lookups) for every request. This CPU-intensive cryptographic operation and database/cache lookups for token revocation or API key validation can overwhelm a single server.
- Horizontal scaling: Add more authentication servers behind a load balancer to distribute token validation load.
- Stateless tokens (JWT): Use JWTs to avoid database lookups on every request by embedding claims and using signature verification.
- Caching: Cache public keys for JWT signature verification and token revocation lists in fast distributed caches like Redis.
- Token expiration: Use short-lived tokens to reduce the need for revocation checks.
- API Gateway: Offload authentication to an API gateway or edge service to reduce backend load.
- Sharding: For API key storage or token revocation data, shard the data across multiple databases or caches.
- CDN for keys: Distribute public keys globally via CDN to speed up JWT verification in multiple regions.
- At 1 million users, assuming 1 request per second each, that is 1 million requests/sec.
- Each JWT signature verification takes ~1-5 ms CPU time; 1 million QPS requires thousands of CPU cores or horizontal scaling.
- API key lookups require fast cache or DB queries; Redis can handle ~100K ops/sec per instance, so multiple instances needed.
- Network bandwidth depends on token size (~1 KB); 1 million QPS = ~1 GB/s bandwidth just for tokens.
- Storage for token revocation lists depends on token lifetime and user count; short-lived tokens reduce storage needs.
Start by explaining the authentication flow simply. Identify the main components: token issuance, validation, and revocation. Discuss how load grows with users and requests. Point out the CPU cost of cryptographic checks and database lookups as bottlenecks. Then propose solutions like stateless JWTs, caching, horizontal scaling, and API gateways. Always justify why each solution fits the bottleneck.
Your database handles 1000 QPS for API key validation. Traffic grows 10x to 10,000 QPS. What do you do first?
Answer: Add a caching layer (e.g., Redis) in front of the database to serve API key validation requests faster and reduce DB load. If traffic continues to grow, horizontally scale the cache and authentication servers.
Practice
Solution
Step 1: Understand the role of authentication
Authentication is about confirming who is making the request, not about encryption or speed.Step 2: Identify the correct purpose
Verifying the client's identity ensures only authorized users access the API.Final Answer:
To verify the identity of the client accessing the API -> Option AQuick Check:
Authentication = Verify identity [OK]
- Confusing authentication with encryption
- Thinking authentication speeds up API
- Mixing authentication with logging
Solution
Step 1: Recall JWT structure
A JWT token consists of three parts separated by dots: header, payload, and signature.Step 2: Match the correct format
Only the format with three dot-separated parts matches JWT.Final Answer:
header.payload.signature -> Option AQuick Check:
JWT = header.payload.signature [OK]
- Confusing JWT with basic auth format
- Using equal signs instead of dots
- Mixing API key format with JWT
Solution
Step 1: Understand OAuth token refresh response
A successful refresh returns a new access token and expiry time.Step 2: Identify the success response
{"access_token": "abc123", "expires_in": 3600} contains a valid access token and expiry, indicating success.Final Answer:
{"access_token": "abc123", "expires_in": 3600} -> Option DQuick Check:
Success = new access token returned [OK]
- Confusing error response with success
- Expecting refresh token in response
- Assuming null access token means success
Solution
Step 1: Analyze API key usage in URLs
URLs are often logged by servers, browsers, and proxies, risking key exposure.Step 2: Identify the security risk
Embedding API keys in URLs can leak them unintentionally, causing security warnings.Final Answer:
API keys in URLs can be logged or leaked easily -> Option CQuick Check:
API key in URL = risk of leakage [OK]
- Thinking API keys must be encrypted always
- Believing API keys can't authenticate
- Assuming keys expire too fast
Solution
Step 1: Identify secure JWT handling practices
Short-lived tokens reduce risk if stolen; HTTPS protects data in transit; signature validation ensures token integrity.Step 2: Evaluate options for security
Use short-lived JWTs with HTTPS and validate signature on each request follows all best practices; others expose security risks like token theft or tampering.Final Answer:
Use short-lived JWTs with HTTPS and validate signature on each request -> Option BQuick Check:
Secure JWT = short life + HTTPS + signature check [OK]
- Storing JWTs insecurely in localStorage
- Sending tokens in URLs risking leaks
- Skipping signature validation
Ready to prove it?
Pass the test and this pattern moves unknown
